PhpStorm: get code inspection warnings for & ldquo; Methods with the same name as their class will not be constructors & rdquo;

advertisements

Okay I've finally switched to PHP7. My code is a bit old and will be refurbished. Some of the problems are:

class MagicClass
    function MagicClass(){
        //etc
    }

Which gives an deprecation warning during execution:

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; MagicClass has a deprecated constructor in

This is good:

class MagicClass
    function __construct(){
        //etc
    }


How can I get PhpStorm code inspection to warn me for such errors in my current codebase?


It does not look like PhpStorm v10 supports this specific case. It has "PHP 7 Compatibility" inspection but it does not flag this code in any way (regardless what PHP Language Level you choose -- be it 5.6 or 7).

The solution is to install "Php Inspection (EA Extended)" plugin -- it has such inspection and it will work even if you choose 5.x as PHP Language level.

Please note: this plugin has a lot of inspections, some of which you may consider wrong/useless etc .. so you may have a need to go trough each additional inspection provided by this plugin and disable it if needed.