Category
stdlib
Problem
PHP 8.4 adds mb_scrub(string $string, ?string $encoding = null): string — replace invalid byte sequences with ? (or U+FFFD for UTF-8) for the given encoding. Mail sanitizers, log pipelines, and HTTP body normalizers use it alongside mb_convert_encoding() (#3075).
Maintainer audit (Jun 2026): function_exists('mb_scrub') → false on bin/vm.php.
php-src reference
Repro (failure today)
Save as test/repro-maintainer/parity_mb_scrub.php:
<?php
var_export(function_exists('mb_scrub'));
// Invalid UTF-8 byte
echo mb_scrub("\xFF", 'UTF-8'), "\n";
// Valid UTF-8 unchanged
echo mb_scrub("café", 'UTF-8'), "\n";
// Default encoding (internal)
echo mb_scrub("\xFF"), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_mb_scrub.php
php bin/vm.php test/repro-maintainer/parity_mb_scrub.php 2>&1 | head -5
'
| Runtime |
function_exists |
scrub \xFF UTF-8 |
valid café |
| Zend PHP 8.4+ |
true |
? or U+FFFD |
unchanged |
bin/vm.php |
false |
fatal |
— |
php-src-strict enum operand
<?php
enum E: string { case A = 'x'; }
try {
mb_scrub(E::A, 'UTF-8');
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
Must throw catchable TypeError (mirror #5873 mb_strlen pattern), not silent backing-string coercion.
Scope (PHP-in-PHP first)
| Path |
Work |
ext/mbstring/mb_scrub.php |
Algorithm in PHP using existing mbstring module (#5695) |
ext/mbstring/Module.php |
Register function |
ext/mbstring/VmMbstring.php |
Shared invalid-byte scrub helper (reuse for #6038 MIME if applicable) |
| JIT/AOT |
VM-only v1 |
Avoid: new logic in runtime/*.c.
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter MbScrub'
Related
Category
stdlibProblem
PHP 8.4 adds
mb_scrub(string $string, ?string $encoding = null): string— replace invalid byte sequences with?(or U+FFFD for UTF-8) for the given encoding. Mail sanitizers, log pipelines, and HTTP body normalizers use it alongsidemb_convert_encoding()(#3075).Maintainer audit (Jun 2026):
function_exists('mb_scrub')→ false onbin/vm.php.php-src reference
ext/mbstring/mbstring.c—PHP_FUNCTION(mb_scrub)ext/mbstring/mbstring.stub.php— signature +$encodingdefault (null→ internal encoding)ext/mbstring/libmbfl— invalid-sequence detection / substitutionRepro (failure today)
Save as
test/repro-maintainer/parity_mb_scrub.php:function_exists\xFFUTF-8cafétrue?or U+FFFDbin/vm.phpfalsephp-src-strict enum operand
Must throw catchable
TypeError(mirror #5873mb_strlenpattern), not silent backing-string coercion.Scope (PHP-in-PHP first)
ext/mbstring/mb_scrub.phpext/mbstring/Module.phpext/mbstring/VmMbstring.phpAvoid: new logic in
runtime/*.c.Done when
function_exists('mb_scrub')→ true on VM$string→TypeError(php-src-strict)test/compliance/cases/stdlib/mb_scrub.phptgreen./script/ci-fast.sh --filter MbScrubgreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter MbScrub'Related