Fopen with / without @ before this

I saw code samples that use @ to fopen , as in

 $fh = @fopen($myFile, 'w'); 

What is the meaning of this @ ?

+4
source share
3 answers

It suppresses errors that an expression can display.

You can find out more about this.

Example:

 file_get_contents('file_does_not_exist'); //this shows an error @file_get_contents('file_does_not_exist'); //this does not 
+9
source

PHP error management property char.

PHP supports one error control statement: the at sign (@). When added to an expression in PHP, any error messages that may be generated by this expression will be ignored .

More details here .

+5
source

Using @ is always a bad practice. It will suppress the error message if it occurs, while error messages are extremely useful for the programmer, and suppression is suicide. The fate of PHP should be used mainly not by programmers, but by random users who have no idea. You have this code from one of the last. So, it’s better to get rid of all @ , so you can see what happened and fix the error.
Please note that each error message has a specific meaning and explains what the problem is. For example, you might have a file system permission issue or setting PHP OPEN_BASEDIR to prevent the file from opening. Thus, the error message tells you what to do. Error messages are good, and @ is evil.

+1
source

Source: https://habr.com/ru/post/1305336/


All Articles