Last modified: 2011-07-08 02:24:24 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T26159, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 24159 - Remove uses of the error suppression operator
Remove uses of the error suppression operator
Status: NEW
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
unspecified
All All
: Low minor (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks: code_quality
  Show dependency treegraph
 
Reported: 2010-06-28 15:04 UTC by Chad H.
Modified: 2011-07-08 02:24 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
List for the lazy (5.05 KB, text/plain)
2010-06-29 12:28 UTC, Chad H.
Details
Try 2 (7.25 KB, text/plain)
2010-06-29 12:34 UTC, Chad H.
Details

Description Chad H. 2010-06-28 15:04:38 UTC
"Error suppression operators have lots of implementation issues in PHP, they are evil and should almost never be used."

and 

"Don't use the error suppression (@) operator for any reason ever. It's broken when E_STRICT is enabled and it causes an unlogged, unexplained error if there is a fatal, which is hard to support. Use wfSuppressWarnings() and wfRestoreWarnings() instead."

Somebody should go through MediaWiki and remove the 87 uses of it and replace it with appropriate error checking. Things like array indexes can be checked with isset(), some things should actually get wfSuppressWarnings() and wfRestoreWarnings() (permission errors on file operations are a good example).

Tagging this easy for somebody with some spare time.
Comment 1 Sam Reed (reedy) 2010-06-29 06:30:09 UTC
Dump of the what files/lines for the lazy? :P
Comment 2 Chad H. 2010-06-29 12:28:01 UTC
Created attachment 7523 [details]
List for the lazy

$ grep -irPn '@[a-z]+\(' . | grep -v .svn | grep -v 'Binary file' > ~/uses-of-@.txt
Comment 3 Chad H. 2010-06-29 12:29:04 UTC
It has one false positive, an @import in CSS, but it's commented anyway :)
Comment 4 Chad H. 2010-06-29 12:34:38 UTC
Created attachment 7524 [details]
Try 2

Forgot to include _ in [a-z]+. This version includes it :)
Comment 5 Sam Reed (reedy) 2010-06-29 12:42:10 UTC
./includes/normal/UtfNormalTest.php:77:	if( preg_match( '/@Part([\d])/', $data, $matches ) ) {

Would be another ;)
Comment 6 Chad H. 2010-07-02 19:46:24 UTC
$ grep -irPn '@[a-z_]+\(' .

This only includes global function calls, which isn't the only place @ can be used :)

$ grep -irPn '@[a-z_]+::'

Yields 1 static method call. Similar grep for method on object calls came back negative, yay :)

$ grep -irn '@\$' . | grep -v .svn | grep -v 'Binary file'

Gives you a bunch of variable accessing with @ that I didn't include above :(
Comment 7 thetooth 2010-10-03 16:29:50 UTC
A better solution is to use php's scream flag which overrides the suppression symbol.

Add a statement to the main construct after the configuration has been loaded and have it call "ini_set('scream.enabled', true);" if a debug flag is set, that way developers can catch all errors regardless of another dev's coding style.
Comment 8 Niklas Laxström 2010-10-03 16:47:28 UTC
It's an PECL extension which requires PHP 5.2.0. I don't see how that is a solution to this bug.
Comment 9 Chad H. 2010-10-03 18:48:07 UTC
(In reply to comment #8)
> It's an PECL extension which requires PHP 5.2.0. I don't see how that is a
> solution to this bug.

It's not. We shouldn't be using a PECL extension to get around poor coding.
Comment 10 Sam Reed (reedy) 2011-02-10 16:53:49 UTC
How many more of these are still about....?
Comment 11 Chad H. 2011-02-10 17:04:00 UTC
Too many :(
Comment 12 Chad H. 2011-05-15 14:35:19 UTC
Using r88187:

$ php checkSyntax.php
Building file list...done.
Checking syntax (using  php -l, this can take a long time)
Warning in file /opt/local/apache2/htdocs/phase3/includes/api/ApiParse.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/api/ApiQuery.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/api/ApiQueryBacklinks.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/api/ApiQueryExternalLinks.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/cache/MessageCache.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/ConfEditor.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/db/Database.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/db/DatabaseIbm_db2.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/db/DatabaseMysql.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/db/DatabasePostgres.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/diff/DairikiDiff.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/filerepo/ForeignAPIFile.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/filerepo/FSRepo.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/filerepo/LocalFile.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/filerepo/LocalRepo.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/GlobalFunctions.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/HistoryBlob.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/Import.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/json/Services_JSON.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/media/DjVu.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/media/Exif.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/media/SVG.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/objectcache/SqlBagOStuff.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/parser/Parser.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/parser/Parser_LinkHooks.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/profiler/Profiler.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/Revision.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/Sanitizer.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/search/SearchMySQL.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/search/SearchSqlite.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/Setup.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/specials/SpecialLockdb.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/specials/SpecialUnlockdb.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/specials/SpecialWantedpages.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/StreamFile.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/templates/Userlogin.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/includes/User.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/languages/Language.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/backup.inc: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/checkImages.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/checkSyntax.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/importImages.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/importUseModWiki.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/language/StatOutputs.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/Maintenance.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/proxy_check.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/rebuildFileCache.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/storage/fixBug20757.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/updateSearchIndex.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/updateSpecialPages.php: Error supression operator (@) found.
Warning in file /opt/local/apache2/htdocs/phase3/maintenance/userOptions.inc: Error supression operator (@) found.
Comment 13 thetooth 2011-05-16 08:45:11 UTC
haha, oh wow
Comment 14 Chad H. 2011-07-06 22:02:09 UTC
As of r91609:

$ php maintenance/checkSyntax.php 
Building file list...done.
Checking syntax (using  php -l, this can take a long time)
Warning in file /www/phase3/includes/filerepo/ForeignAPIFile.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/json/Services_JSON.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/libs/jsminplus.php: trailing ?> found.
Warning in file /www/phase3/includes/media/Exif.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/parser/Parser.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/parser/Parser_LinkHooks.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/profiler/Profiler.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/Revision.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/Sanitizer.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/search/SearchMySQL.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/search/SearchSqlite.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/Setup.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/specials/SpecialWantedpages.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/StreamFile.php: Error supression operator (@) found.
Warning in file /www/phase3/includes/User.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/backup.inc: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/checkImages.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/importImages.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/importUseModWiki.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/language/StatOutputs.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/Maintenance.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/proxy_check.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/storage/fixBug20757.php: Error supression operator (@) found.
Warning in file /www/phase3/maintenance/userOptions.inc: Error supression operator (@) found.

Done! 1134 files checked, 0 failures and 24 warnings found
Comment 15 Chad H. 2011-07-06 22:07:46 UTC
(In reply to comment #14)
> As of r91609:
> 
> $ php maintenance/checkSyntax.php 
> Building file list...done.
> Checking syntax (using  php -l, this can take a long time)
> Warning in file /www/phase3/includes/filerepo/ForeignAPIFile.php: Error
> supression operator (@) found.

Scratch that one, fixed in r91611.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links