-
Notifications
You must be signed in to change notification settings - Fork 529
Improve create conditional expressions to handle all expressions #2007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve create conditional expressions to handle all expressions #2007
Conversation
d17c4c1
to
5b9cf52
Compare
Issue bot seems not working well. Looks like a cache problem? |
hmm I have the impression it works: https://github.com/phpstan/phpstan-src/actions/runs/3488347704 |
Oh, thank you for noticing! Not sure what I was looking at... |
@ondrejmirtes |
Loops are generalised and skipped after a couple of iterations AFAIK. Could that be related? |
Not that "loop" I think. |
fa64209
to
e3c84ef
Compare
Ah sorry, yeah, completely wrong loop I was thinking about.. xD |
472df61
to
b2bea90
Compare
This pull request has been marked as ready for review. |
Thank you! |
return $field; | ||
} | ||
|
||
if (count($row) === 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems to cache result of function result 1:1 and retrive the result from cache later. I observed this in phpstan v 1.9.2 (the latest rel).
Is that desired? For count()
it is legit and thank you. However for expression like TraitUtil::hasTrait($object, DebugTrait::class)
(a custom function) how does php know/guarantee the result will be the same, does it reason it based on the TraitUtil::hasTrait
impl or just guess it when the passed args are the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is intended
how does php know/guarantee the result will be the same
When
- TraitUtil::hasTrait is not marked impure
- The exact same
TraitUtil::hasTrait($object, DebugTrait::class)
is called - $object is not invalidated
just guess it when the passed args are the same?
so it's something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, remembering function results was working before this PR already.
https://phpstan.org/blog/remembering-and-forgetting-returned-values
this PR made them work for more complex conditions too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I did not know user functions are "pure"/remembered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request covers
phpstan/phpstan#8360
improves result of phpstan/phpstan#4173 but not completely fixed yet