What is the use of the @ symbol in PHP?


I have seen uses of @ in front of certain functions, like the following:

$fileHandle = @fopen($fileName, $writeAttributes);

What is the use of this symbol?

12/6/2015 11:32:06 AM

Accepted Answer

It suppresses error messages — see Error Control Operators in the PHP manual.

12/28/2016 8:16:06 AM

It suppresses errors.

See Error Control Operators in the manual:

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.

If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @...

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow