1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 10:43:30 +02:00
Files
archived-php-src/Zend/tests/lazy_objects/skipLazyInitialization_default.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

60 lines
1.0 KiB
PHP

--TEST--
Lazy objects: skipLazyInitialization() marks property as non-lazy and sets default value if any
--FILE--
<?php
class C {
public $a;
public $b = 1;
public $c;
}
function test(string $name, object $obj) {
printf("# %s\n", $name);
$reflector = new ReflectionClass(C::class);
$reflector->getProperty('a')->skipLazyInitialization($obj);
$reflector->getProperty('b')->skipLazyInitialization($obj);
var_dump($obj->a);
var_dump($obj->b);
var_dump(!$reflector->isUninitializedLazyObject($obj));
var_dump($obj);
}
$reflector = new ReflectionClass(C::class);
$obj = $reflector->newLazyGhost(function () {
throw new \Exception('initializer');
});
test('Ghost', $obj);
$obj = $reflector->newLazyProxy(function () {
throw new \Exception('initializer');
});
test('Proxy', $obj);
?>
--EXPECTF--
# Ghost
NULL
int(1)
bool(false)
lazy ghost object(C)#%d (2) {
["a"]=>
NULL
["b"]=>
int(1)
}
# Proxy
NULL
int(1)
bool(false)
lazy proxy object(C)#%d (2) {
["a"]=>
NULL
["b"]=>
int(1)
}