Skip to content

AOT: mb_substr()/mb_strcut() refuse runtime encoding — LogicException (leftover of #34256, ext/mbstring/mbstring.c) #34875

Description

@PurHur

Category

bug · AOT · stdlib · mbstring · php-src-strict

Problem

mb_substr() / mb_strcut() NestedJIT already accepts runtime string/offsets (#34256) but still requires a compile-time encoding literal. A runtime encoding (e.g. $argv[1] or non-folded concat) aborts compile with LogicException instead of matching Zend/VM. Invalid encoding names throw LogicException at compile time instead of catchable ValueError.

Repro Zend 8.2+ VM AOT (master)
mb_substr("あいう", 1, 1, $argv[1]) with UTF-8 い い LogicException at compile
mb_substr("abc", 0, 1, "NOPE") in try/catch ValueError ValueError LogicException at compile

Peer closed: #34870 (mb_chr/ord), #34866 (mb_strpos family), #34858 (mb_strtolower/toupper), #34625 (mb_strlen). ./script/aot-smoke.sh is 8/8.

php-src reference

  • php/php-src ext/mbstring/mbstring.c — PHP_FUNCTION(mb_substr) / PHP_FUNCTION(mb_strcut)
  • Encoding arg validates via mbstring encoding registry → ValueError on invalid names

PHP implementation target

  • ext/mbstring/mb_substr.php (JitMbSubstr) / ext/mbstring/JitMbStrcut.php — encodingPtr + NestedJIT assertEncodingArgv (peer JitMbSearch / JitMbCase)
  • ext/mbstring/MbStrcutJitHelper.php + lib/JIT/Builtin/MbStrcut.php — compile assert helper; no new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
TMP=$(mktemp -d)
cat >"$TMP/t.php" <<PHP
<?php
\$e = \$argc > 1 ? \$argv[1] : ("UTF-"."8");
echo mb_substr("あいう", 1, 1, \$e), "\\n";
PHP
php bin/vm.php "$TMP/t.php" UTF-8
php bin/compile.php -o "$TMP/t.bin" "$TMP/t.php"
'

Done when

  • AOT matches Zend/VM for runtime encoding on mb_substr / mb_strcut
  • Invalid encoding → catchable ValueError (Argument Stdlib: round, sqrt, gettype and expanded PHPT specs #4), not compile-time LogicException
  • Targeted phpunit / AOT fixture green; ./script/aot-smoke.sh stays 8/8
  • No new runtime/*.c

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:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions