Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does the @ become useful?

As you know, the @ characters before a php istruction suppress every eventual warning, error or notice from being raised.

Personally, i dont like this tecnique, becose i prefer to handle those errors, and in a real life, the error must no happen or have to be managed.

By the way, i find this tecnique to be applied in many scripts (cms plugins, open-source classes).

So, could the @ really be useful (in this case, an example would be appreciated), or is just for lazy developers?

like image 314
Strae Avatar asked Mar 27 '10 19:03

Strae


People also ask

When can a material become useful?

Answer: material become useful when it is used in limit but fan material is used in excess it is harmful for both humans and environment.

What makes a material useful?

Useful material - Material that still has or retains useful properties including materials that can be reused, recyclables, organics that can be composted, materials used for making fuel, material used for construction or land reclamation, and material used productively in the operation of a landfill.

How does a material become harmful?

These substances could be dusts, gases or fumes that you breathe in, or liquids, gels or powders that come into contact with your eyes or skin. There could also be harmful micro-organisms present that can cause infection, an allergic reaction or are toxic.


1 Answers

Just think of, for example, a failed mysql_connect call. You may want to suppress the error message otherwise shown to the user (also showing some details you usually don't want anybody else to see) in this case.

Though the PHP warning was suppressed via the @-sign, you can perform certain actions like showing a friendly error message to the user afterwards.

However "misusing" @ for things like in the example below is definitely not a good idea:

@$undefinedVariable .= 'some text';

There are far more examples for bad use of the error-suppression sign out there than the one above, you should only use it when there is no other, better way to achieve what you want.

like image 193
lamas Avatar answered Sep 21 '22 04:09

lamas