Reputation: 3122
What does following statement means
$tmp = @$_GET['myValue'];
Can somebody please provide detailed explanation on above statement?
Upvotes: 0
Views: 286
Reputation: 14873
@ : to avoid warning
$_GET : An associative array of variables passed to the current script via the URL parameters.
myval : parameter
--
example
http://example.com/?myval=test
echo @$_GET['myval']; will echo test
http://example.com/
echo @$_GET['myval']; will be null
//php 5.4 way is
var_dump(isset($_GET['myValue']) ? : null);
Upvotes: 0
Reputation: 4879
The @ symbol is an error suppressor operator. It is not recommended to use it everywhere. Also, it is twice slower than the isset() function. See full reference for the @ error control operator at http://php.net/manual/en/language.operators.errorcontrol.php
Upvotes: 3
Reputation: 255015
It assigns value of GET parameter myValue
into tmp
if exists. If not - then tmp = null
PS: it is a bad practice. Better way to do the same is:
$tmp = isset($_GET['myValue']) ? $_GET['myValue'] : null;
Upvotes: 1