<?php
echo mb_strlen('é', 'UTF-8'), "\n";
// Zend accepts null to mean "use internal encoding".
try {
var_dump(mb_strlen('hello', null));
} catch (Throwable $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}
// Invalid encoding should match Zend (warning/ValueError + return false).
try {
var_dump(mb_strlen('hello', 'NO_SUCH_ENCODING'));
} catch (Throwable $e) {
echo get_class($e), ": ", $e->getMessage(), "\n";
}
Category
stdlibProblem
mb_strlen()exists but has compiler-specific constraints (UTF-8/ASCII/8BIT-only in JIT path; other encodings depend on host mbstring, and error handling differs). For parity and portability we need php-src-consistent behavior for:$encoding(string, null, omitted)ValueErrordepending on PHP version)$encodingomitted)php-src reference
ext/mbstring/mbstring.c—PHP_FUNCTION(mb_strlen)ext/mbstring/php_mbstring.h— encoding tables and option parsingext/mbstring/tests/mb_strlen*.phptRepro (today)
Scope (this repo)
ext/types/mb_strlen.php+ext/types/JitMbStrlen.php+ native helpers underlib/AOT/runtime/Done when
$encodingacceptsnull/omitted like Zend and follows internal encoding rules