-
-
Notifications
You must be signed in to change notification settings - Fork 938
Open
Labels
Description
Feature request
A colleague of mine caught a bug that used $$this->methodCall(). I know the phpstan/phpstan-strict-rules plugin can ban the use of $$, however I think PHPStan, out of the box, should prohibit $$this. Given $this always refers to an instance of a class, and not a string, it can't possibly be used as the lookup for something on the symbol table.
I played around with this in 3v4l.org, $$this just produces NULL, which PHPStan (0.12.81) does not pickup on to stop the method call. Consider the following code (available at https://3v4l.org/mhr52):
<?php
declare(strict_types=1);
final class Greeter
{
public function greet(): void
{
echo $$this->greetText();
}
public function greetText(): string
{
return 'Hello World';
}
}
$g = new Greeter();
$g->greet();You will get the following PHP error when trying to run:
Fatal error: Uncaught Error: Object of class Greeter could not be converted to string in /in/mhr52:9
However, PHPStan (with --level=max) will not report any issues.
Reactions are currently unavailable