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

Ken Guest:
Scan your code for old-style constructors using PHPUnit
Nov 06, 2015 @ 17:53:26

Ken Guest has a quick post on his site with a helpful hint for those updating older codebases. You can use PHPUnit & PHP_CodeSniffer to locate old constructors in the PHP4 format (constructors named after the classes).

There are less than seven days left until PHP 7 is released, which drops support for old-style constructors – the ones where a method is a constructor if it shares the same name as the class. You don’t want to spend too much time scrolling through codebases for that though do you? Better things to do, like watch videos of conference talks you’ve missed and such. Well, you’re in luck. If you use php_codesniffer (and if you don’t, well shame on you), you’ll be able to get a report of old-style constructors fairly quickly.

He includes examples of the commands you'll need to use to sniff out these older constructors, making use of the built-in "Squiz" coding standard and the "Generic.NamingConventions.ConstructorName" sniff but only on PHP files. He also shows how to alias it to a bash command and export the results to a CSV file.

tagged: scan code legacy constructor php4 php7 phpunit phpcodesniffer

Link: https://kenguest.wordpress.com/2015/11/06/scan-your-code-for-old-style-constructors-using-phpunit/


Trending Topics: