Consider this code:

<?php declare(strict_types = 1);

class Test3
{
}

$t3 = new Test3(1);

Here, I'm calling a non-existing constructor.

PHP Tools does not detect this, PHPStan does detect it and reports:

Class Test3 does not have a constructor and must be instantiated without any parameters.

Another example of what is not detected is:

<?php declare(strict_types = 1);

class Test3
{
    public function __construct(int $a)
    {
        $a++;
    }
}

$t3 = new Test3(1, 2);

PHPStan does detect it.

Suggestion

Please detect and report wrong constructor calls.

(I hope my reports here don't occur as offensive to you; my intention is not to say "PHPStan" is better, but solely to help improving the already awesome PHP Tool 🙂)

8 days later

@UweKeim the feedback is highly appreciated! our goal is to help developers, and if this helps you, then we're happy to implement it :)

UweKeim this is actually not an error nor warning in PHP, but we'll definitely add a diagnostic for it.

@UweKeim latest pre-release adds diagnostic for missing __construct, working on the rest of the diagnostics ...

Write a Reply...