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

Skip to content

[ExpressionLanguage] Deprecate loose comparisons when using the "in" operator #49064

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

Merged
merged 1 commit into from
Jan 23, 2023

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jan 22, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? no
Deprecations? yes
Tickets -
License MIT
Doc PR -

Twig already uses strict comparisons for its "in" operator. Using loose comparisons can be a foot-gun, since eg "foo" is currently "in" ["bar", true]. I propose to trigger a deprecation in v6.3 and make the comparison strict in v7.0.

The deprecation is not really actionable but I don't have a better idea that doesn't involve adding a new operator, and I can't find something that'd be better than "in".

I propose to merge as is and see later on with feedback from the community if we need more.

Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I guess a user can take two actions:

  • Normalize the array parameter so it'll only have the expected types
  • Implement their own expression function if they really have to deal with loose matching

Let's "document" these in the UPGRADE guide?

@nicolas-grekas
Copy link
Member Author

I guess a user can take two actions:

Good call, I added your suggestions in the deprecation message directly

@nicolas-grekas nicolas-grekas merged commit 28cce83 into symfony:6.3 Jan 23, 2023
@nicolas-grekas nicolas-grekas deleted the el-in-strct branch January 23, 2023 15:54
@fabpot fabpot mentioned this pull request May 1, 2023
nicolas-grekas added a commit that referenced this pull request Jul 4, 2023
…xandre-daubois)

This PR was merged into the 7.0 branch.

Discussion
----------

[ExpressionLanguage] Remove deprecated code paths

| Q             | A
| ------------- | ---
| Branch?       | 7.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | _NA_
| License       | MIT
| Doc PR        | symfony/symfony-docs#18486

- The `in` and `not in` operators now use strict comparison #49064

Commits
-------

7050bc8 [ExpressionLanguage] Remove deprecated code paths
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