Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Request #18751 Confusing error message from autoloader
Submitted: 2011-08-23 14:01 UTC
From: meijuh Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 3 + 22 = ?

 
 [2011-08-23 14:01 UTC] meijuh (Jeroen Meijer)
Description: ------------ If a Sniff does not adhere strictly to a class name format PHP will throw a fatal error (Cannot redeclare class). PHPCS' autoloader will try to autoload the class twice, resulting in a cannot redeclare error message. Which is very confusing; classes which does not adhere to a format like '<code_standard>_<sniff_type>_<sniff_name>, (I think) should not be autoloaded. Or a clearer error/warning message should be thrown by PHPCS. Test script: --------------- 1. Create a new code standard: 'Test'. 2. Create the folder Sniffs 3. Create a Sniff inside this folder named TestSniff.php and name the class TestSniff (not Test_TestSniff!) 4. Create a ruleset and a rule Test.TestSniff 5. Run phpcs --standard=Test TestSniff.php Expected result: ---------------- Code standard violations of TestSniff.php. Actual result: -------------- PHP Fatal error: Cannot redeclare class TestSniff in /usr/share/php/PHP/CodeSniffer/Standards/Test/Sniffs/TestSn iff.php on line 4 PHP Stack trace: PHP 1. {main}() /usr/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:38 PHP 3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:542 PHP 4. PHP_CodeSniffer->populateTokenListeners() /usr/share/php/PHP/CodeSniffer.php:448 PHP 5. PHP_CodeSniffer::autoload() /usr/share/php/PHP/CodeSniffer.php:0

Comments

 [2012-09-19 23:28 UTC] cklfp (Filip Paço)
Thanks, it solved may problem :). Great work.
 [2016-10-31 04:26 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
Closing as autoloader has been rewritten, and namespaces enforced, from 3.0 onwards.