mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
offsetSet did not account for the fact that the array may no longer exist after the field is overwritten. This fixes that. Add test of resizing both to the empty array and a smaller array - there should be no valgrind warnings with a proper fix. Alternate approach to #7486 (described in https://bugs.php.net/bug.php?id=81429)
56 lines
833 B
PHP
56 lines
833 B
PHP
--TEST--
|
|
SplFixedArray::setSize in offsetSet destructor (#81429)
|
|
--FILE--
|
|
<?php
|
|
$values = new SplFixedArray(1);
|
|
$values->offsetSet(0, new HasDestructor());
|
|
$values->offsetSet(0, false);
|
|
echo "Done\n";
|
|
|
|
class HasDestructor {
|
|
public function __destruct() {
|
|
global $values;
|
|
var_dump($values);
|
|
$values->setSize($values->getSize() - 1);
|
|
var_dump($values);
|
|
}
|
|
}
|
|
|
|
$values->setSize(5);
|
|
$values->offsetSet(4, new HasDestructor());
|
|
echo "Done\n";
|
|
--EXPECT--
|
|
object(SplFixedArray)#1 (1) {
|
|
[0]=>
|
|
bool(false)
|
|
}
|
|
object(SplFixedArray)#1 (1) {
|
|
[0]=>
|
|
bool(false)
|
|
}
|
|
Done
|
|
Done
|
|
object(SplFixedArray)#1 (5) {
|
|
[0]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
[3]=>
|
|
NULL
|
|
[4]=>
|
|
object(HasDestructor)#2 (0) {
|
|
}
|
|
}
|
|
object(SplFixedArray)#1 (4) {
|
|
[0]=>
|
|
NULL
|
|
[1]=>
|
|
NULL
|
|
[2]=>
|
|
NULL
|
|
[3]=>
|
|
NULL
|
|
}
|