Skip to content

[Php74] Align mb_str_split() polyfill with Mbstring and native#640

Merged
nicolas-grekas merged 1 commit into
1.xfrom
mbstring-phpnn-divergence
Jul 1, 2026
Merged

[Php74] Align mb_str_split() polyfill with Mbstring and native#640
nicolas-grekas merged 1 commit into
1.xfrom
mbstring-phpnn-divergence

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member

Refs #624.

mb_str_split() is polyfilled by both Php74 and Mbstring, 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() returned false for a length lower than 1 even on PHP 8+, where the function raises a ValueError.
  • It built a single .{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 the Php74 copy with it and with native:

                               native                       Php74 (before)   Php74 (after)
mb_str_split('победа', 0)      ValueError                   false            ValueError
mb_str_split(str_repeat('x',70000), 70000)   [70000 chars]  false (+warning) [70000 chars]

The other overlapping functions (mb_str_pad in Php83, mb_ucfirst/mb_lcfirst/mb_trim/mb_ltrim/mb_rtrim in Php84) were checked against Mbstring and native and already behave identically, so they are left untouched.

Tests exercise Php74::mb_str_split() directly, since the Php74 polyfill is only the active provider of the global function on PHP < 7.4, where the PHP 8 path is unreachable through the global.

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.
@nicolas-grekas nicolas-grekas merged commit e91b176 into 1.x Jul 1, 2026
40 checks passed
@nicolas-grekas nicolas-grekas deleted the mbstring-phpnn-divergence branch July 1, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants