php-src/Zend/tests/lazy_objects/fetch_op_error.phpt
Arnaud Le Blanc 58aa6fc830
Lazy objects
RFC: https://wiki.php.net/rfc/lazy-objects

Closes GH-15019
2024-08-30 17:30:03 +02:00

62 lines
1 KiB
PHP

--TEST--
Lazy objects: property op error
--FILE--
<?php
class C {
public int $a = 1;
public function __construct() {
var_dump(__METHOD__);
$this->a = 2;
}
}
function test(string $name, object $obj) {
printf("# %s:\n", $name);
var_dump($obj);
try {
var_dump($obj->a++);
} catch (Error $e) {
printf("%s: %s\n", $e::class, $e->getMessage());
}
var_dump($obj);
}
$reflector = new ReflectionClass(C::class);
$obj = $reflector->newLazyGhost(function ($obj) {
throw new Error("initializer");
});
test('Ghost', $obj);
$obj = $reflector->newLazyProxy(function ($obj) {
throw new Error("initializer");
});
test('Proxy', $obj);
--EXPECTF--
# Ghost:
lazy ghost object(C)#%d (0) {
["a"]=>
uninitialized(int)
}
Error: initializer
lazy ghost object(C)#%d (0) {
["a"]=>
uninitialized(int)
}
# Proxy:
lazy proxy object(C)#%d (0) {
["a"]=>
uninitialized(int)
}
Error: initializer
lazy proxy object(C)#%d (0) {
["a"]=>
uninitialized(int)
}