php-src/ext/standard/tests/strings/substr_replace_array_unset.phpt
Niels Dossche 4bbbe6d652
Fix substr_replace with slots in repl_ht being UNDEF
The check that was supposed to check whether the array slot was UNDEF
was wrong and never triggered. This resulted in a replacement with the
empty string or the wrong string instead of the correct one. The correct
check pattern can be observed higher up in the function's code.

Closes GH-10323

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-15 15:31:34 +00:00

27 lines
461 B
PHP

--TEST--
substr_replace() function - array with unset
--FILE--
<?php
$replacement = ['A', 'C', 'B'];
unset($replacement[1]);
$newarr = substr_replace(['1 string', '2 string'], $replacement, 0);
print_r($newarr);
$replacement = ['foo', 42 => 'bar', 'baz'];
unset($replacement[42]);
$newarr = substr_replace(['1 string', '2 string'], $replacement, 0);
print_r($newarr);
?>
--EXPECT--
Array
(
[0] => A
[1] => B
)
Array
(
[0] => foo
[1] => baz
)