phpstan
phpstan copied to clipboard
Method return value not recognized when calling an other method in between
trafficstars
Code snippet that reproduces the problem
https://phpstan.org/r/88b4ba76-8196-4568-9da7-943ea5b5695b
Expected output
Should detect valid not-null array here, as it does when you remove $this->doSomething(); here.
Did PHPStan help you today? Did it make you happy in any way?
Working hard to increase 2 levels this week :)
PHPStan forgets that you set $this->member = [] because $this->doSomething() is void and therefore impure (it might change the property type to something else).
This might be solved in the future but right now it isn't.
@gregor-tb After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:
@@ @@
-18: Method HelloWorld::getIT() should return array but returns array|null.
+18: Method HelloWorld::getIT() should return array<mixed> but returns array<mixed>|null.
Full report
| Line | Error |
|---|---|
| 18 | `Method HelloWorld::getIT() should return array |