Weekly PECL Package – Scream
This is the first of what is planned to be a weekly post on a more or less random PECL package. The idea is for me to get to know some PECL packages in more detail and for you to get to know some PECL packages in more detail – without losing your precious time.
For the first edition of this series I will cover the relatively new PECL package aptly named Scream. The purpose of this extension is to, well, scream. It will disable the the silence operator (@) so that any hidden errors will still be shown. After this, you may scream at whoever used the silence operator in the first place – thus the name Scream (Just kidding?).
Lets get started…
1 | che-hodginss-macbook-pro:~ chehodgins$ sudo pecl install scream-alpha |
After a few minutes…
1 2 3 | Build process completed successfully Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/scream.so' install ok: channel://pecl.php.net/scream-0.1.0 |
Great, now add it to php.ini and restart apache:
1 2 | extension=scream.so scream.enabled=1 |
Check phpinfo and we are ready to go:

I'm new to macs and just discovered taking screenshots of portions of the screen (Apple key ⌘ + Shift + 4). Very cool.
Now we will borrow some code from some open source projects that use the silence operator and see what happens.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ini_set('display_errors', 1); error_reporting(E_ALL | E_STRICT); echo 'starting... '; // Initialize $host = $user = $password = $sock = $port = $errno = $errstr = $response = ''; // From Joomla! if (!($resource = @mysql_connect( $host, $user, $password, true ))) { // ... } // From Wordpress $response .= @ fread ( $sock, 8192 ); // From Joomla! @ dl('bz2.so'); // From Wordpress $sock = @fsockopen($host, $port, $errno, $errstr); echo "done.\n"; ?> |
With scream.enabled = 0 we get this lovely output:
1 2 3 | che-hodginss-macbook-pro:www chehodgins$ php -f scream.php starting... done. che-hodginss-macbook-pro:www chehodgins$ |
And with scream.enabled = 1:
1 2 3 4 5 6 7 8 9 10 | che-hodginss-macbook-pro:www chehodgins$ php -f scream.php starting... Warning: fread(): supplied argument is not a valid stream resource in /Users/chehodgins/www/scream.php on line 17 Warning: dl(): Unable to load dynamic library '/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20050922/bz2.so' - (null) in /Users/chehodgins/www/scream.php on line 20 Warning: fsockopen() expects parameter 2 to be long, string given in /Users/chehodgins/www/scream.php on line 23 done. che-hodginss-macbook-pro:www chehodgins$ |
It is obvious at this moment that in general it is not advisable to use the silence operator. Most PHP programmers have been burnt by this a few times and usually will be much more harsh towards those think this feature is useful. I can recall spending lots of time bug hunting before finding an @ which lead me to a simple error. Its a painful experience, don’t do it.
As a programmer you may already steer clear of the silence operator but much code is inherited. Because of the simplicity of the silence operator it can be hard to track down where it is used in your code. Try searching for ‘@’ in one of your projects, how many thousands of results do you get? That is one reason to install this on your dev box and find those tough bugs before they hit production.
And just in case you are still not convinced, check out Five reasons the shut-up operator (@) should be avoided by Derick Rethans
-
Christoph Dorn
