php-src/ext/spl/tests/SplObjectStorage_unserialize_reference.phpt
Tyson Andre 032de9e001 Optimize SplObjectStorage native read/write/has/unset dimension handlers
This makes reading/writing with `$splObjectStorage[$offset]` shorthand twice as
fast as it was previously, and a bit faster than offsetGet/offsetSet instead of
(previously) much slower.

Call destructor after overriding old SplObjectStorage entry.
Previously, it was called before, which was possibly unsafe
if the destructor had side effects.

Add tests.

Closes GH-7695

Related to GH-7690

Check for ref in SplObjectStorage->__unserialize, check for ref.

SplObjectStorage->unserialize may be a different cause of references
for malformed inputs, so continue checking

In internally used methods, convert references to non-references if they're
found.
2021-11-30 09:09:12 -05:00

42 lines
684 B
PHP

--TEST--
SPL: Test that __unserialize converts references to non-references
--FILE--
<?php
$s = new SplObjectStorage();
$y = 1;
$o = new stdClass();
$x = [$o, &$y];
$s->__unserialize([$x, []]);
var_dump($s);
$val = $s[$o];
$val = 123;
var_dump($s);
?>
--EXPECT--
object(SplObjectStorage)#1 (1) {
["storage":"SplObjectStorage":private]=>
array(1) {
[0]=>
array(2) {
["obj"]=>
object(stdClass)#2 (0) {
}
["inf"]=>
int(1)
}
}
}
object(SplObjectStorage)#1 (1) {
["storage":"SplObjectStorage":private]=>
array(1) {
[0]=>
array(2) {
["obj"]=>
object(stdClass)#2 (0) {
}
["inf"]=>
int(1)
}
}
}