Category
Stdlib · php-src-strict · string replace array subject · pillar 4
Problem
str_replace / str_ireplace accept array|string $subject. When $subject is an array of mixed scalars, Zend string-casts each element and replaces. VM/JIT throw LogicException: str_replace() array subject values must be strings in this compiler build (same for str_ireplace).
Verified 2026-08-03 at e0e5e10c9 (Docker Zend 8.2.32):
| Repro |
Zend 8.2.32 |
VM / JIT |
str_replace('1', 'X', [12, '13']) |
['X2', 'X3'] |
LogicException: str_replace() array subject values must be strings… |
str_ireplace('a', 'X', ['a', 12, 'A']) |
['X', '12', 'X'] |
LogicException: str_ireplace() array subject values must be strings… |
Peer of the preg_* non-string array-subject gap (same “must be strings in this compiler build” pattern).
php-src reference
PHP implementation target
ext/standard/ string replace helpers + VM/JIT lowering — coerce array subject values to string like Zend; delete LogicException guard
- PHP-in-PHP; no new
runtime/*.c
Repro
./script/docker-exec.sh -- bash -lc 'cat > /tmp/str_replace_mixed.php << "PHP"
<?php
var_export(str_replace("1", "X", [12, "13"]));
echo "\n";
var_export(str_ireplace("a", "X", ["a", 12, "A"]));
echo "\n";
PHP
php /tmp/str_replace_mixed.php
php bin/vm.php /tmp/str_replace_mixed.php
php bin/jit.php /tmp/str_replace_mixed.php'
Done when
Category
Stdlib· php-src-strict · string replace array subject · pillar 4Problem
str_replace/str_ireplaceacceptarray|string$subject. When$subjectis an array of mixed scalars, Zend string-casts each element and replaces. VM/JIT throwLogicException: str_replace() array subject values must be strings in this compiler build(same forstr_ireplace).Verified 2026-08-03 at
e0e5e10c9(Docker Zend 8.2.32):str_replace('1', 'X', [12, '13'])['X2', 'X3']LogicException: str_replace() array subject values must be strings…str_ireplace('a', 'X', ['a', 12, 'A'])['X', '12', 'X']LogicException: str_ireplace() array subject values must be strings…Peer of the preg_* non-string array-subject gap (same “must be strings in this compiler build” pattern).
php-src reference
ext/standard/string.c—php_str_replace_common/ array subject walkext/standard/basic_functions.stub.php—str_replace/str_ireplacesignaturesPHP implementation target
ext/standard/string replace helpers + VM/JIT lowering — coerce array subject values to string like Zend; deleteLogicExceptionguardruntime/*.cRepro
Done when
LogicExceptionfor int array subject valuestest/repro/guard; php-src-strict