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

PHPMaster.com:
Why Suppressing Notices is Wrong
Dec 24, 2012 @ 19:35:30

On PHPMaster.com there's a new article that suggests that suppressing notices thrown from your code is a bad practice to get into, both through error reporting and the use of the suppression operator, "@".

The PHP notice suppression operator is somewhat of a controversial topic in many circles. Some overuse it, some don’t use it at all, and some don’t even know it exists. Apologies in advance for the horrible code you’re about to witness in this article, but it serves a purpose to illustrate the usefulness (or lack thereof) of the suppression operator.

He talks about some of the common notices and how the suppression operator prevents the "Notice" message that could come out of it. They suggest, however, that there's never a good time to use the operator, especially during development. Obviously, there are a few cases (they point out one with mail) where it could be useful. There's also some sample code for a custom error handler you can use to capture the issues that might come up.

tagged: error notice suppression development

Link:

ThinkPHP Blog:
Silence of the LAMPs
Sep 16, 2009 @ 14:13:40

In a recent post to the ThinkPHP blog Martin Brotzeller looks at a PHP operator that developers should just not use anymore - the suppression operator (@).

The silence operator exists to give programmers an easy way to suppress messages when a command might fail and the code checks for success itself (i.e. in those cases that raise errors instead of throwing exceptions).

He points out a popular use (like putting it on an fopen to prevent it from throwing an E_WARNING) but notes that this could cause trouble if the code is several layers deep and seems to fail silently. He gives en example of the Zend_Loader component of the Zend Framework and how, if the suppression operator was used, errors with an include failed without so much as a blip in the error log. While it seems handy, the suppression operator can cause more harm than good in the long run.

tagged: suppression operator avoid

Link:

Johannes Schluter's Blog:
Scream!
Feb 27, 2009 @ 17:14:50

After being tasked with some code that was filled with the suppression character (@) all over, Johannes Schluter decided to take matters into his own hands and write an extension to disable it.

That's annoying. So I wrote a simple extension disabling this operator. That helped. I then proposed that extension to pecl, while doing that I found out that Gopal has written a similar extension before. After short discussions we added that extension, using the name scream to pecl and released the extension there.

Documentation for the extension has already been added to the PHP manual for the "Break the Silence" operator. By enabling the setting (either in your php.ini or via an ini_set) turning on "scream_enabled", any use of the suppression operator (@) will be nulled out and all according error messages will be displayed.

tagged: screan suppression operator pecl extension remove phpini

Link:


Trending Topics: