Skip to content

Stdlib: mb_substr / mb_strpos / mb_strtolower — mbstring beyond mb_strlen (ext/mbstring parity) #3239

Description

@PurHur

Category

stdlib

Problem

Only mb_strlen() is registered (ext/types/mb_strlen.php). Multibyte string manipulation — required for UTF-8 web apps and #3222 charset work — is missing:

  • mb_substr, mb_strpos, mb_strrpos, mb_strtolower, mb_strtoupper
  • mb_strlen with explicit encoding (verify parity)

php-src reference

  • ext/mbstring/mbstring.cphp_mb_substr, php_mb_strpos, case conversion
  • ext/mbstring/php_unicode.c — UTF-8 codepoint iteration
  • ext/standard/basic_functions.cstrlen fallback when mbstring disabled

Repro (today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_dump(function_exists(\"mb_substr\"));"
php bin/vm.php -r "echo mb_substr(\"café\", 0, 2, \"UTF-8\");"
'

Zend PHP (mbstring): bool(true); prints ca (or codepoint-safe slice per encoding)
This compiler: Call to undefined function mb_substr()

Compare with working mb_strlen:

php bin/vm.php -r "echo mb_strlen(\"café\");"

Scope (this repo)

Layer Files Notes
VM ext/types/mb_substr.php, VmMbstring.php UTF-8 v1 via mb_* polyfill or host ext/mbstring when embedding Zend for dev
Module ext/types/Module.php or ext/standard/Module.php Register mb_* family
JIT defer VM-only v1
Tests test/compliance/cases/mb_substr_utf8.phpt Non-ASCII fixtures

v1 encoding: UTF-8 only; other encodings → ValueError or documented subset.

Done when

  • mb_substr('café', 0, 2, 'UTF-8') matches Zend on VM
  • mb_strpos, mb_strtolower registered with compliance PHPTs
  • ./script/ci-fast.sh --filter mb_substr green
  • docs/capabilities.md lists mb_* rows

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter mb_substr'

Dependencies

Links

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 machineenhancementNew feature or requestimplementation-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