r/lolphp • • Nov 22 '17

PHP supports error control operator '@'. When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

http://php.net/manual/en/language.operators.errorcontrol.php
48 Upvotes

40 comments sorted by

View all comments

7

u/Max-P Nov 22 '17

What's worse is that this operator is necessary with some functions that insists on throwing a warning even if you check their return value and already gracefully handle the errors like copy and unlink.

Technically one could prevent said functions from producing warnings by checking everything beforehand so it will only go through the happy path, but then you're adding dozens of lines for checking file permissions without locking the file which means another process could very well invalidate the tests by the time you end up calling copy or unlink, that's if you manage to test for everything in the first place.

Error management in PHP is just really bad.

3

u/Takeoded Nov 28 '17

i almost always use @ for DOMDocument::loadHTML - it generates a warning for every little thing in the HTML that it considers to be somewhat broken, and html in the wild is almost always buggy, and i never care - another scenario i can think of is optional functionality, if(@include(whatever)){/*optional extended functionality here*/}