Skip to content

Regression: mb_substr/mb_strpos/mb_str_split/… invalid encoding LogicException — Zend ValueError (re-#13377, ext/mbstring) #27945

Description

@PurHur

Category

Regression · php-src-strict · ext/mbstring invalid ``

Problem

After #13377 fixed mb_strtoupper/mb_strtolower (and mb_strlen/mb_convert_case already match), several mbstring APIs still throw a compiler-private LogicException for an unknown encoding instead of Zend’s ValueError.

Call (Zend 8.2.32 / HEAD bf5802236, 2026-08-06) Zend VM / PROFILE=8.4
mb_substr('a',0,1,'nope') ValueError: … must be a valid encoding, \"nope\" given LogicException: mb_substr requires mbstring for encoding nope…
mb_strpos('a','a',0,'nope') ValueError (arg #4) LogicException: mbstring search requires…
mb_str_split('a',1,'nope') ValueError (arg #3) LogicException
mb_strcut / mb_strimwidth / mb_strwidth ValueError LogicException
mb_stripos / mb_strrpos / mb_strripos ValueError LogicException
mb_strstr / mb_stristr / mb_strrchr / mb_strrichr ValueError LogicException
mb_str_pad(..., 'nope') (PROFILE≥8.4) ValueError LogicException

Already green (do not regress): mb_strlen, mb_strtoupper, mb_strtolower, mb_convert_case.

php-src reference

PHP implementation target

  • Shared encoding-validation helper used by the listed builtins in ext/mbstring/ (and JIT lowering if separate) — throw Zend-identical ValueError, not LogicException
  • PHP-in-PHP only — no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'cat > /tmp/mb_enc_valueerror.php <<'"'"'PHP'"'"'
<?php
foreach ([
  fn() => mb_substr(\"a\", 0, 1, \"nope\"),
  fn() => mb_strpos(\"a\", \"a\", 0, \"nope\"),
  fn() => mb_str_split(\"a\", 1, \"nope\"),
] as $i => $fn) {
  try { $fn(); echo \"$i ok\n\"; }
  catch (Throwable $e) { echo $i, \" \", get_class($e), \": \", $e->getMessage(), \"\n\"; }
}
PHP
php /tmp/mb_enc_valueerror.php
php bin/vm.php /tmp/mb_enc_valueerror.php'

Done when

  • Listed APIs throw Zend-identical ValueError (message + arg index) on VM (and JIT when in scope)
  • No LogicException / "in this compiler build" for invalid encodings
  • Compliance or test/repro/ guard covering at least mb_substr + mb_strpos + mb_str_split
  • php-src-strict; no php-compiler-strict shortcut

Trust snapshot (this maintainer run)

  • bootstrap-inventory --check: OK 7075/7075
  • make north-star5-verify-fast: OK
  • make bootstrap-selfhost-helloworld: OK (Hello World)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions