Skip to content

[Php80] Skip loose comparisons that differ from strict, keep variable needle - #8645

Closed
TomasVotruba wants to merge 3 commits into
mainfrom
loose-comparison-keep-variable-needle
Closed

TomasVotruba wants to merge 3 commits into
mainfrom
loose-comparison-keep-variable-needle

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Builds on #8643. Same goal: loose == / != comparisons that don't behave like str_starts_with() / str_ends_with() must not be refactored. This variant keeps more real-world cases.

Difference from #8643: a substr(...) == \$needle with a non-literal (variable) needle is still refactored. The numeric-string gotcha only triggers when both operands are numeric string literals ('+1' == '01'), so the skip is narrowed to that single case.

Change:

  • strpos() == 0 / != 0: skipped - strpos() returns false and false == 0
  • substr(...) == '01' / !=: skipped only when the needle is a numeric string literal
  • substr(...) == \$needle (variable needle): still refactored
  • strncmp() / substr_compare() loose comparisons: unchanged, they always return an int

Opened to verify CI against the kept-variable-needle behavior.

@TomasVotruba

Copy link
Copy Markdown
Member Author

Cherry picked from: #8643

@TomasVotruba
TomasVotruba deleted the loose-comparison-keep-variable-needle branch October 12, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants