Skip to content

Stdlib: mb_internal_encoding() / mb_language() / mb_http_input() — encoding defaults (ext/mbstring parity) #4636

Description

@PurHur

Category

stdlib · php-src-strict

Problem

Encoding configuration builtins from ext/mbstring are missing. Frameworks read/set internal encoding and language at bootstrap (mb_internal_encoding('UTF-8'), mb_language('uni')). Without these, multibyte pipelines cannot mirror Zend defaults.

Verified 2026-06-19: function_exists('mb_internal_encoding')false on bin/vm.php. mb_strlen / mb_substr / mb_trim exist but cannot follow Zend encoding state until this lands.

Blocks (downstream)

Issue Symptom without mb_internal_encoding
#9977 mb_trim($s, characters: '-') after mb_internal_encoding('UTF-8')
#9208 Full mb_ltrim/mb_rtrim UTF-8 mask repro
#6548 mb_send_mail charset negotiation

php-src reference

Repro (failure today)

<?php
var_dump(function_exists('mb_internal_encoding'));
echo mb_internal_encoding(), "\n";
mb_internal_encoding('UTF-8');
echo mb_internal_encoding(), "\n";
var_dump(mb_language());
var_dump(mb_http_input());
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_mb_internal_encoding.php
php bin/vm.php repro_mb_internal_encoding.php
'
Runtime First mb_internal_encoding()
Zend e.g. UTF-8
This compiler undefined function ❌

Encoding propagation probe (done-when guard)

<?php
mb_internal_encoding('UTF-8');
$s = '  üñîçø∂é  ';
var_dump(mb_strlen($s));
var_dump(mb_trim($s));

Scope (PHP-in-PHP first)

Path Work
ext/mbstring/VmMbstring.php Store/retrieve internal encoding + language in PHP state
ext/mbstring/mb_internal_encoding.php Builtin registration (getter/setter)
ext/mbstring/mb_language.php, mb_http_input.php Stub parity subset
ext/mbstring/Module.php Wire functions
ext/mbstring/mb_strlen.php, mb_trim.php, … Read encoding from shared state (not hard-coded UTF-8)
JIT/AOT VM-first v1; JIT calls same PHP helpers

No new runtime/*.c — thin FFI only if ICU/libc charset probe unavoidable.

Done when

  • function_exists('mb_internal_encoding') true; getter returns Zend-default encoding string
  • mb_internal_encoding('UTF-8') setter succeeds and changes mb_strlen / mb_trim results on non-ASCII sample above
  • mb_language() get/set subset matches Zend for uni / Japanese names
  • mb_http_input() returns expected string or false per Zend when no HTTP input
  • test/compliance/cases/stdlib/mb_internal_encoding.phpt green
  • ./script/ci-fast.sh --filter mb_internal_encoding green
  • Unblocks Stdlib: mb_trim()/mb_ltrim()/mb_rtrim() — PHP 8.4 named characters param + new builtins (ext/mbstring/mbstring.c) #9977 encoding probe (comment cross-link when green)

Verification

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

Related

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