Retain non-variable expression types in closure#1929
Retain non-variable expression types in closure#1929ondrejmirtes merged 1 commit intophpstan:1.9.xfrom
Conversation
|
The webmozart assert extension failures are interesting. Did you decipher those already? Maybe I added invalid closure phpdoc somewhere or so? |
|
The type of There's 2 obvious solutions (if this PR was to go through): unroll the foreach into 3 separate resolvers, or extract the string resolver into a variable and use that instead. |
ondrejmirtes
left a comment
There was a problem hiding this comment.
This isn't the right solution. You don't know when the callable will be called so it's correct to invalidate $this->foo even if it was checked against null outside of the closure - it can be null again inside.
Function_exists() is special in this regard, because there's no way to unload a function in PHP, so it should "survive" when entering closure.
|
If this isn't desirable, I'd like your opinion on the discrepancy between closures and arrow functions: https://phpstan.org/r/4241be28-13e8-49d0-bc6e-298a99f88df9 |
|
Please see: #1934 (comment) |
|
I think to solve the bug report, we need to opt-in just a few specific expressions to retain their type when entering an anonymous function:
|
c5326f9 to
ebf6cab
Compare
Looking at ondrrej's example in #1934 (comment) same thing can be said for arrow functions (like https://3v4l.org/bp59b) |
|
Because I tried to always add the |
|
Thank you! |
Fix phpstan/phpstan#8205