You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
After further experimentation, it seems this would work if you have __toString, so perhaps PHPStan could check for that method's existence, and if it's not defined, reject $$this?
Activity
ancarda commentedon Mar 17, 2021
After further experimentation, it seems this would work if you have
__toString, so perhaps PHPStan could check for that method's existence, and if it's not defined, reject$$this?ondrejmirtes commentedon Mar 17, 2021
Hi, this is very easy to implement.
$scope->getType($variable->name)when$variable->nameis Expr$type->toString()isErrorType, report the error.ancarda commentedon Mar 17, 2021
Thank you @ondrejmirtes! I'll give it a go tonight. I'd love to be able to finally contribute something to PHPStan!
ondrejmirtes commentedon Mar 20, 2021
There's also the opportunity to catch the same problem with
$foo->{$method}()etc.Updated PHPStan to commit f71b938503c3244953c1914d465c8a9a510242cc
phpstan-bot commentedon Sep 20, 2026
Closed via merging phpstan/phpstan-src#5871
github-actions commentedon Oct 22, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.