Category
stdlib (PCRE) | php-src-strict for enum operands
Problem
preg_replace_callback() exists (#1177), but the array-of-patterns variant is missing.
$out = preg_replace_callback_array(
['/\d+/' => fn($m) => '['.$m[0].']'],
'a1b2'
);
echo $out;
Today: Call to undefined function preg_replace_callback_array().
Zend PHP 8.2: prints a[1]b[2].
Once implemented, enum-case subject operands must TypeError (not LogicException / silent backing coerce) per ext/pcre/php_pcre.c — same php-src-strict policy as #7153 / #7154.
php-src reference
Repro — missing function
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "echo function_exists(\"preg_replace_callback_array\") ? \"yes\" : \"no\";"'
# today: no
Save as test/repro-maintainer/preg_replace_callback_array.php:
<?php
$out = preg_replace_callback_array(
['/\d+/' => fn(array $m): string => '[' . $m[0] . ']'],
'a1b2'
);
echo $out, "\n";
Repro — enum subject (after basic impl; php-src-strict)
<?php
enum E: string { case A = 'x'; }
try {
preg_replace_callback_array(['/x/' => fn($m) => 'y'], E::A);
} catch (Throwable $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
Zend: TypeError naming E. VM today: undefined function (later: must not LogicException).
Scope
| Path |
Work |
ext/standard/preg_replace_callback_array.php |
VM builtin — reuse VmPregReplaceCallback / VmPreg internals |
ext/standard/VmPreg.php |
subject guard via VmString::coerceStringBuiltinArg() + enum case rejection |
ext/standard/Module.php |
register |
ext/standard/JitPregReplaceCallback.php |
JIT follow-up optional v1 |
| Tests |
test/compliance/cases/stdlib/preg_replace_callback_array.phpt |
| Tests |
test/compliance/cases/stdlib/preg_replace_callback_array_enum.phpt (php-src-strict) |
Done when
Notes
Build on existing preg_replace_callback() VM/JIT infrastructure in ext/standard/VmPreg*.php. Pairs #6639 (JIT wiring) and #5999 (enum batch for other preg_*).
Category
stdlib (PCRE) | php-src-strict for enum operands
Problem
preg_replace_callback()exists (#1177), but the array-of-patterns variant is missing.Today:
Call to undefined function preg_replace_callback_array().Zend PHP 8.2: prints
a[1]b[2].Once implemented, enum-case subject operands must
TypeError(notLogicException/ silent backing coerce) perext/pcre/php_pcre.c— same php-src-strict policy as #7153 / #7154.php-src reference
ext/pcre/php_pcre.c—PHP_FUNCTION(preg_replace_callback_array)ext/pcre/php_pcre.c—php_pcre_replace_impl()subjectZ_PARAM_STR/ enum rejectionpreg_replace_callback()but iterates pattern=>callback mapRepro — missing function
Save as
test/repro-maintainer/preg_replace_callback_array.php:Repro — enum subject (after basic impl; php-src-strict)
Zend:
TypeErrornamingE. VM today: undefined function (later: must not LogicException).Scope
ext/standard/preg_replace_callback_array.phpVmPregReplaceCallback/VmPreginternalsext/standard/VmPreg.phpVmString::coerceStringBuiltinArg()+ enum case rejectionext/standard/Module.phpext/standard/JitPregReplaceCallback.phptest/compliance/cases/stdlib/preg_replace_callback_array.phpttest/compliance/cases/stdlib/preg_replace_callback_array_enum.phpt(php-src-strict)Done when
a[1]b[2]on VMpreg_replace_callback_arraytestsTypeErrorwith enum class name (php-src-strict)./script/ci-fast.sh --filter preg_replace_callback_arraygreenVMmin; JIT follow-up optional)Notes
Build on existing
preg_replace_callback()VM/JIT infrastructure inext/standard/VmPreg*.php. Pairs #6639 (JIT wiring) and #5999 (enum batch for other preg_*).