1
0
mirror of https://github.com/php/php-src.git synced 2026-04-25 17:08:14 +02:00
Files
archived-php-src/Zend/tests/lazy_objects/fetch_dynamic_prop_initializes.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

66 lines
1.1 KiB
PHP

--TEST--
Lazy objects: property fetch of dynamic property initializes object
--FILE--
<?php
#[AllowDynamicProperties]
class C {
public int $a;
public function __construct() {
var_dump(__METHOD__);
}
}
function test(string $name, object $obj) {
printf("# %s:\n", $name);
var_dump($obj);
var_dump(@$obj->dynamic);
var_dump($obj);
}
$reflector = new ReflectionClass(C::class);
$obj = $reflector->newLazyGhost(function ($obj) {
var_dump("initializer");
$obj->__construct();
});
test('Ghost', $obj);
$obj = $reflector->newLazyProxy(function ($obj) {
var_dump("initializer");
return new C();
});
test('Proxy', $obj);
--EXPECTF--
# Ghost:
lazy ghost object(C)#%d (0) {
["a"]=>
uninitialized(int)
}
string(11) "initializer"
string(14) "C::__construct"
NULL
object(C)#%d (0) {
["a"]=>
uninitialized(int)
}
# Proxy:
lazy proxy object(C)#%d (0) {
["a"]=>
uninitialized(int)
}
string(11) "initializer"
string(14) "C::__construct"
NULL
lazy proxy object(C)#%d (1) {
["instance"]=>
object(C)#%d (0) {
["a"]=>
uninitialized(int)
}
}