For those who do not know, in short, the role of the operator @ is to hide errors. Meaning:
Assuming that the file 'adsasd.php' does not exist
$a = fopen ('adsasd.php', 'r')
will give a Warning: fopen (adsasd.php) [function.fopen]: failed to open ...
but if we write
$a = @fopen ('adsasd.php', 'r');
not receive the error and $a will become false
The operator is quite flexible and may be made almost everywhere. For example,
... If we have
$ a = 2.3;
$ b = 0,
$ c = $ a / $ b; Warning: Division by zero in ... on line ...
... But if we put
$ a = 2.3;
$ b = 0,
@ $ c = $ a / $ b;
error no longer occurs and $c gets value false
Why is not advisable to use this operator?
Well, in the latter case, assuming that we forget to initialize the value of $b, the result (the $c) will always have value 0 (false) regardless of the variable $a, which, in some cases, the result is not expected .
If we do not really need this operator, it is advisable to do so:
* error_reporting (E_ALL) during development of a project to see any error (even Notice)
* error_reporting (0) to hide any error if our website is publec. In this case, we must frequently check logs (Apache and PHP)
why we use @ in php
@ is used in php to hide error msg
for ex:
<?
@ function msg(){
//this fun displays error;
echo "hide error msg"
}
?>
why we use @
@ is warning error should hold from compiler , the warring is not show use @
example
@number_format($this->var);
1.number_format function variable not in number ,
2.php version variation
php
ok
why to use (or not) the @
For those who do not know, in short, the role of the operator @ is to hide errors. Meaning:
Assuming that the file 'adsasd.php' does not exist
$a = fopen ('adsasd.php', 'r')
will give a Warning: fopen (adsasd.php) [function.fopen]: failed to open ...
but if we write
$a = @fopen ('adsasd.php', 'r');
not receive the error and $a will become false
The operator is quite flexible and may be made almost everywhere. For example,
... If we have
$ a = 2.3;
$ b = 0,
$ c = $ a / $ b; Warning: Division by zero in ... on line ...
... But if we put
$ a = 2.3;
$ b = 0,
@ $ c = $ a / $ b;
error no longer occurs and $c gets value false
Why is not advisable to use this operator?
Well, in the latter case, assuming that we forget to initialize the value of $b, the result (the $c) will always have value 0 (false) regardless of the variable $a, which, in some cases, the result is not expected .
If we do not really need this operator, it is advisable to do so:
* error_reporting (E_ALL) during development of a project to see any error (even Notice)
* error_reporting (0) to hide any error if our website is publec. In this case, we must frequently check logs (Apache and PHP)
Share Your Answers