Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Debuggable Blog:
Supressing Errors in PHP
Jan 30, 2009 @ 17:14:58

Felix Geisendorfer has posted two new items to the Debuggable blog looking at suppressing errors in your applications - and no, that doesn't mean using the @ operator either.

As of late I am getting sick of some best practices I have taught myself. Never using the @-error suppressing operator quickly moving to the top of the list. Before you start crying out loud (I know you will), let me say this: I do not mean to encourage anybody to use the @-operator. Applying the practice herein introduced may result in permanent damage to your coding habits and could serve as a gateway behavior to writing shitty code.

He gives an example in the first post of a place where he failed to properly check to ensure an element existed before checking a element of it. The second post provides an interesting solution to the same problem - using empty on the element/subelement to check its existence.

tagged: suppress error empty isset check exist shutup operator symbol

Link:

Derick Rethans' Blog:
Five reasons why the shut-op operator (@) should be avoided
Jan 05, 2009 @ 18:09:37

Derick Rethans has posted just a few of the reasons why the "shut-up operator" (the @ symbol) should be avoided at all costs in your PHP applications.

The @-operator is often used to silence errors in noisy PHP functions—functions that generate warnings that can not be easily prevented. [...] In those cases, there is no way how to check up-front whether the function call will not issue a warning when being called.

There are side effects to using the operator, however, including hiding legitimate errors and making debugging that much more difficult. To back up his point, he includes four other reasons to avoid the operator's use (besides the debugging issues):

  • It's slow (part 1)
  • It's slow (part 2)
  • It's slow (part 3: It generates crappier code)
  • Apfelstrudels were harmed (related to the strudel_token in the C code for the operator)
tagged: shutup operator atsign avoid reason slow debugging error hide

Link:


Trending Topics: