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 56 57
|
--TEST--
Lazy objects: Destructor exception in resetAsLazy*()
--FILE--
<?php
class C {
public readonly int $a;
public function __construct() {
$this->a = 1;
}
public function __destruct() {
throw new \Exception(__METHOD__);
}
}
$reflector = new ReflectionClass(C::class);
print "# Ghost:\n";
$obj = new C();
try {
$reflector->resetAsLazyGhost($obj, function ($obj) {
var_dump("initializer");
$obj->__construct();
});
} catch (\Exception $e) {
printf("%s: %s\n", $e::class, $e->getMessage());
}
// Object was not made lazy
var_dump(!$reflector->isUninitializedLazyObject($obj));
print "# Proxy:\n";
$obj = new C();
try {
(new ReflectionClass($obj))->resetAsLazyProxy($obj, function ($obj) {
var_dump("initializer");
return new C();
});
} catch (\Exception $e) {
printf("%s: %s\n", $e::class, $e->getMessage());
}
// Object was not made lazy
var_dump(!(new ReflectionClass($obj))->isUninitializedLazyObject($obj));
?>
--EXPECT--
# Ghost:
Exception: C::__destruct
bool(true)
# Proxy:
Exception: C::__destruct
bool(true)
|