Skip to content

[Php80] Skip empty string needle in StrContainsRector - #8460

Merged
TomasVotruba merged 1 commit into
mainfrom
worktree-fix-9886-str-contains-empty-needle
Sep 4, 2026
Merged

[Php80] Skip empty string needle in StrContainsRector#8460
TomasVotruba merged 1 commit into
mainfrom
worktree-fix-9886-str-contains-empty-needle

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9886

StrContainsRector rewrites strpos()/strstr() !== false to str_contains(). But with an empty string needle the two are not equivalent:

  • On PHP < 8, strpos($haystack, '') returned false, so strpos($haystack, '') !== false was false.
  • str_contains($haystack, '') returns true.

So the conversion silently changed behavior for empty needles. This skips the rule when the needle is an empty string literal.

Added two skip fixtures for strpos and strstr.

https://claude.ai/code/session_01Hczn76uiK4bDwdHM4rTMui

strpos()/strstr() with empty needle returned false on PHP < 8, while
str_contains() with empty needle returns true, so the conversion changed
behavior. Skip when the needle is an empty string literal.

Claude-Session: https://claude.ai/code/session_01Hczn76uiK4bDwdHM4rTMui
@TomasVotruba
TomasVotruba merged commit b9d85b9 into main Sep 4, 2026
43 checks passed
@TomasVotruba
TomasVotruba deleted the worktree-fix-9886-str-contains-empty-needle branch September 4, 2026 16:32
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.

StrContainsRector PHP7.4 => PHP8.0 upgrade

1 participant