1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
--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) {
}
}
|