Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP escaping error reporting with @

I am currently refactoring some code for work and I have come across some function calls prefixed by the "@" symbol. As I understand it, this is intended to escape PHP error reporting if the call fails.

Is this type of thing good practice? I understand the rationale in a development environment but when the site is pushed to production shouldn't all errors be handled properly rather than just escaped?

The use of this symbol would therefore mean that the developer has to sort through the code at a later stage to remove all error reporting escapes.

I am unsure whether to remove these symbols and just find a better way to handle potential errors or not.

For clarity, the function this was used on was the native PHP fsockopen() function.

like image 505
Evernoob Avatar asked May 01 '26 03:05

Evernoob


1 Answers

That's probably among the worst practices you can come across in php code. It basically tells the interpreter to suppress errors and just try to do whatever the code asks it to do regardless of the outcome.

A great way to drag yourself and fellow teammates into all-nighter phantom bug hunts once the app has grown substantially.

Try-catch with custom exception handling is the way to go.

like image 160
code_burgar Avatar answered May 03 '26 15:05

code_burgar