9

In one of my project's configuration settings I observed following two lines at the beginning of file :

@ini_set('memory_limit', '-1');
@set_time_limit(0);

My doubt is what's the difference in the above two lines of code and following lines of code?

ini_set('memory_limit', '-1');
set_time_limit(0);

What's the intention of prefixing @ symbol in PHP?

Please provide me in detail and to the point answer.

Thanks in advance.

NikiC
  • 100,734
  • 37
  • 191
  • 225

2 Answers2

10

@ in php is simply for silencing errors.

for example:

<?php
    $x = 5;
    $y = @$z;

so $y will be null

if you remove the @ it will throw an error.

Tzook Bar Noy
  • 11,337
  • 14
  • 51
  • 82
  • You forgot to mention that the `error_reporting` value in `php.ini` must have the 'bit-flag' `E_WARNING` (value `2`) on it's value. For example, the value `E_ALL`. Check http://php.net/manual/en/function.error-reporting.php for more about this. – Ismael Miguel Dec 25 '14 at 08:47
  • thanks for the comment, now others will see it as well. – Tzook Bar Noy Dec 28 '14 at 10:13
3

Error Control Operators

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

Error Control Operators

i'm PosSible
  • 1,373
  • 2
  • 11
  • 30