Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed

Conversation

ostrolucky
Copy link
Contributor

@ostrolucky ostrolucky commented Dec 15, 2017

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

->raw(', ')
->raw('is_array(')
->compile($this->nodes['right'])
->raw(') ? ')
Copy link
Contributor Author

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

@nicolas-grekas
Copy link
Member

Most traversable are not rewindable. Can't this just create new kinds of issues, thus not improving anything in the end? Just wondering.

@ostrolucky
Copy link
Contributor Author

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.

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Dec 18, 2017
@nicolas-grekas
Copy link
Member

I'm 👎 here because it breaks using the traversable a second time (like for a second "in" check)
That'd be WTF to the end user. Better ask the dev that provides the variables to do this iterator_to_array() call.

@ostrolucky
Copy link
Contributor Author

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.

@nicolas-grekas
Copy link
Member

Eg generators yes.

@ostrolucky
Copy link
Contributor Author

ostrolucky commented Dec 18, 2017

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

@nicolas-grekas
Copy link
Member

A generator is the return value of calling $generator(). This is an example of non rewindable iterator.

@nicolas-grekas
Copy link
Member

https://3v4l.org/FtNnQ

This is just one example of non rewindable iterator.
Definitely no go on my side for this PR. The code should not create more WTFs than it pretends to solve.
Sorry about that.

@ostrolucky ostrolucky force-pushed the expression-in-traversable branch from c26549d to 0192919 Compare December 28, 2017 20:30
@fabpot
Copy link
Member

fabpot commented Dec 31, 2017

Closing for the reasons explained by @nicolas-grekas. Changing this behavior would be a BC break anyway.

@fabpot fabpot closed this Dec 31, 2017
@ostrolucky
Copy link
Contributor Author

ostrolucky commented Dec 31, 2017

Ok. I'll make sure to remind this each time someone introduces \Traversable support in his PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants