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

Bug #19411 magic method error on __construct()
Submitted: 2012-05-08 07:10 UTC
From: vanderhuge Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.3)
PHP Version: 5.3.5 OS: Ubuntu
Roadmaps: (Not assigned)    
Subscription  


 [2012-05-08 07:10 UTC] vanderhuge (Jared Keller)
Description: ------------ Occasionally we've been running into errors where phpcs is reporting valid magic functions as invalid due to the double underscore. "156 | ERROR | Function name "__construct" is invalid; only PHP magic methods should be prefixed with a double underscore"

Comments

 [2012-05-08 09:26 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
I can't replicate this. What exactly does "occasionally" mean? The exact same version of PHPCS, PHP and the code you are checking sometimes produces different results, or that PHPCS used on different setups or code is causing issues? Either way, are you able to provide me with code that I can run PHPCS over to make it fail? Also, what standard are you using? Is it a built-in one or a custom one?
 [2012-05-09 02:02 UTC] vanderhuge (Jared Keller)
Thanks for the quick response - I'll clarify. My occasionally I mean it doesn't error on every __construct() we have and I haven't been able to suss out the pattern of which it has problems with and which it does not. These projects are all hosted on the same server / use the same version of PHP / same version of PHPCS. We use basic PEAR standards without customization. For standards training (punishment?) we occasionally have devs bring a random file under standards - I'll e-mail you a copy of the most recent file we've run into it on.
 [2012-05-11 10:21 UTC] squiz (Greg Sherwood)
Thanks a lot for sending the sample file. The problem is related to the ignore comments. The smallest bit of code to reproduce for me is: /* @codingStandardsIgnoreStart */ class MyClass { /* @codingStandardsIgnoreEnd */ public function __construct() {} }
 [2012-05-11 10:40 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Closed
Fixed in git repo: https://github.com/squizlabs/PHP_CodeSniffer/commit/766f102ca453e685e7a445f28 8043213cb7cde11 Thanks again for the sample file. There is no way I could have tracked this down without it.
 [2012-05-15 00:43 UTC] vanderhuge (Jared Keller)
Outstanding! Will let you know if we encounter any issues with the patch.