mirror of
https://github.com/php/php-src.git
synced 2025-08-17 22:48:57 +02:00

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.
55 lines
No EOL
1.2 KiB
PHP
55 lines
No EOL
1.2 KiB
PHP
--TEST--
|
|
SplObjectStorage unset and destructor edge cases
|
|
--FILE--
|
|
<?php
|
|
class HasDestructor {
|
|
public function __destruct() {
|
|
echo "In destructor. Should no longer be accessible in \$s:\n";
|
|
var_dump($GLOBALS['s']);
|
|
|
|
throw new RuntimeException("thrown from destructor");
|
|
}
|
|
}
|
|
$o = new stdClass();
|
|
$s = new SplObjectStorage();
|
|
$s[$o] = new HasDestructor();
|
|
try {
|
|
unset($s[$o]);
|
|
} catch (Exception $e) {
|
|
echo "Caught: {$e->getMessage()}\n";
|
|
}
|
|
var_dump($s);
|
|
$s[$o] = new HasDestructor();
|
|
try {
|
|
$s->offsetUnset($o);
|
|
} catch (Exception $e) {
|
|
echo "Caught: {$e->getMessage()}\n";
|
|
}
|
|
|
|
var_dump($s);
|
|
?>
|
|
--EXPECT--
|
|
In destructor. Should no longer be accessible in $s:
|
|
object(SplObjectStorage)#2 (1) {
|
|
["storage":"SplObjectStorage":private]=>
|
|
array(0) {
|
|
}
|
|
}
|
|
Caught: thrown from destructor
|
|
object(SplObjectStorage)#2 (1) {
|
|
["storage":"SplObjectStorage":private]=>
|
|
array(0) {
|
|
}
|
|
}
|
|
In destructor. Should no longer be accessible in $s:
|
|
object(SplObjectStorage)#2 (1) {
|
|
["storage":"SplObjectStorage":private]=>
|
|
array(0) {
|
|
}
|
|
}
|
|
Caught: thrown from destructor
|
|
object(SplObjectStorage)#2 (1) {
|
|
["storage":"SplObjectStorage":private]=>
|
|
array(0) {
|
|
}
|
|
}
|