-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ExpressionLanguage] Make in
and not in
handle Traversables
#25506
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
Conversation
ostrolucky
commented
Dec 15, 2017
•
edited
Loading
edited
Q | A |
---|---|
Branch? | master |
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | - |
License | MIT |
Doc PR | symfony/symfony-docs#8880 |
79d0121
to
c26549d
Compare
->raw(', ') | ||
->raw('is_array(') | ||
->compile($this->nodes['right']) | ||
->raw(') ? ') |
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.
I wish I could use ConditionalNode instead of ->raw() for ternary, but this ternary requires FunctionNode inside, for which Parser would have to have functions is_array
and iterator_to_array
registered
Most traversable are not rewindable. Can't this just create new kinds of issues, thus not improving anything in the end? Just wondering. |
That's very edge case. Users can't seriously expect there is a way to check if non-rewindable traversable contains an element without modifying its internal iterator. That's unfixable. ExpressionLanguage is good fit for custom domain DSLs, I think we don't need to expect non rewindable traversables there. |
I'm 👎 here because it breaks using the traversable a second time (like for a second "in" check) |
You say most traversables are non-rewindable. Do you have some of such Class in mind for which this issue applies? I can't find any. Most common object this would help with are doctrine collections, which don't have such issue. I'm really curious, because I've never seen \Traversable for which I couldn't use in iterator_to_array twice in a row. |
Eg generators yes. |
I mean actual class in the wild (e.g. class used in Symfony) I can test it with. This obviously works https://3v4l.org/VMQnX |
A generator is the return value of calling $generator(). This is an example of non rewindable iterator. |
This is just one example of non rewindable iterator. |
c26549d
to
0192919
Compare
Closing for the reasons explained by @nicolas-grekas. Changing this behavior would be a BC break anyway. |
Ok. I'll make sure to remind this each time someone introduces \Traversable support in his PR |