Search code examples
phpoperatorserror-suppression

PHP alias @ function


I'm new to PHP and I'm confused seeing some examples calling a function with a @ prefix like @mysql_ping().

What is it for? Googling / searching is not much of a help since @ gets discarded and 'alias' is not good enough keyword.


Solution

  • @ suppresses errors, warnings and notices.

    You can use it for good purpose if you complement it with a custom error handler or with due check of $php_errormsg variable so you can handle errors properly.

    In my experience, this proper usage is not seen very much and is instead used a lot in the bad way, just to hide errors without acting on them.

    More info at http://www.php.net/manual/en/language.operators.errorcontrol.php