[Php74] Align mb_str_split() polyfill with Mbstring and native#640
Merged
Conversation
The Php74 copy of mb_str_split() returned false for a length lower than 1
even on PHP 8+, where the function raises a ValueError, and used a single
.{N} quantifier that fails to compile for a length above the PCRE 65535
limit. Match the Mbstring implementation: throw ValueError on PHP 8+ and
chunk the regex so both polyfills behave identically.
stof
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #624.
mb_str_split()is polyfilled by bothPhp74andMbstring, and either implementation can end up registered depending on the PHP version and whether ext-mbstring is loaded. The two had drifted:Php74::mb_str_split()returnedfalsefor a length lower than 1 even on PHP 8+, where the function raises aValueError..{N}quantifier, which fails to compile once the length exceeds the PCRE limit of 65535 (preg_split(): Compilation failed: number too big in {} quantifier).Mbstring::mb_str_split()already handles both. This aligns thePhp74copy with it and with native:The other overlapping functions (
mb_str_padinPhp83,mb_ucfirst/mb_lcfirst/mb_trim/mb_ltrim/mb_rtriminPhp84) were checked againstMbstringand native and already behave identically, so they are left untouched.Tests exercise
Php74::mb_str_split()directly, since thePhp74polyfill is only the active provider of the global function on PHP < 7.4, where the PHP 8 path is unreachable through the global.