Category
stdlib · php-src-strict
Problem
preg_replace_callback() replacement string matches Zend, but the optional 5th $count by-ref argument is left at 0 on VM. Closures/limit work; only the out-param is wrong. Likely Internal by-ref binding or VmPregReplaceCallback::invoke write-back (re-#4442 claimed full signature parity).
| Repro |
Zend 8.2 (2026-07-16) |
VM (2026-07-16) |
$c=0; echo preg_replace_callback('/a/', fn($m)=>'A', 'aa', -1, $c).\"|$c\" |
AA|2 |
AA|0 |
same with $limit=2 on 'aaa' |
AAa|2 |
AAa|0 |
php-src reference
PHP implementation target
ext/standard/preg_replace_callback.php — ensure $frame->calledArgs[4] is the user by-ref slot before ->int($count)
ext/standard/VmPregReplaceCallback.php — confirm $replacements write-back; today caller seeds $count=0 then assigns after invoke
- Prefer PHP-in-PHP fix; no new
runtime/*.c logic
Repro
./script/docker-exec.sh -- bash -lc 'php -r '\''$c=0; $r=preg_replace_callback("/a/", fn($m)=>"A", "aa", -1, $c); echo "$r|$c\n";'\'''
./script/docker-exec.sh -- bash -lc 'php bin/vm.php -r '\''$c=0; $r=preg_replace_callback("/a/", fn($m)=>"A", "aa", -1, $c); echo "$r|$c\n";'\'''
Done when
Related
#4442 (closed — full signature) · #10278 (preg_replace count) · #12904 (preg_filter count)
Category
stdlib· php-src-strictProblem
preg_replace_callback()replacement string matches Zend, but the optional 5th$countby-ref argument is left at0on VM. Closures/limit work; only the out-param is wrong. Likely Internal by-ref binding orVmPregReplaceCallback::invokewrite-back (re-#4442 claimed full signature parity).$c=0; echo preg_replace_callback('/a/', fn($m)=>'A', 'aa', -1, $c).\"|$c\"AA|2AA|0$limit=2on'aaa'AAa|2AAa|0php-src reference
ext/pcre/php_pcre.c—PHP_FUNCTION(preg_replace_callback)/php_pcre_preg_replace_impl$countout-parameterPHP implementation target
ext/standard/preg_replace_callback.php— ensure$frame->calledArgs[4]is the user by-ref slot before->int($count)ext/standard/VmPregReplaceCallback.php— confirm$replacementswrite-back; today caller seeds$count=0then assigns after invokeruntime/*.clogicRepro
Done when
AA|2on VM (and JIT/AOT when args ≥5 are lowered)$countremains0when zero replacements.phptundertest/compliance/cases/(or extend existing preg callback cases)Related
#4442 (closed — full signature) · #10278 (
preg_replacecount) · #12904 (preg_filtercount)