What is the use of the @ symbol in PHP?

No comments
The @(the at symbol) symbol in PHP is used to suppress the error reporting for the expression prepended with the @ symbol. However; if track_errors feature is enabled on your server then, any error message generated by the expression will be saved in $php_errormsg variable and this variable gets overwritten on each error. I would suggest, do not use @ symbol, this is not a good practice. Because this symbol does not disappear the error permanently, it just hide the error from the visitors and also is difficult for developer to identify the error.

Let have look at an example below:

echo $_GET['user_id'];
echo @$_GET['user_id'];

The first statement in above code will throw Notice: Undefined index error, however, the second statement will not throw any error at all.
Notice: Undefined index: user_id in F:\localhost\htdocs\test\test.php on line 2

I hope, this tutorial will help you. Please feel free to add your views in the comment box below.

No comments :

Post a Comment