(PHP 8 >= 8.4.0)
ReflectionClass::isUninitializedLazyObject — 检查对象是否为延迟且未初始化的
object
示例 #1 基本用法
<?php
class Example
{
public function __construct(public int $prop) {
}
}
$reflector = new ReflectionClass(Example::class);
$object = $reflector->newLazyGhost(function ($object) {
echo "Initializer called\n";
$object->__construct(1);
});
var_dump($reflector->isUninitializedLazyObject($object));
var_dump($object->prop);
var_dump($reflector->isUninitializedLazyObject($object));
?>
以上示例将输出
bool(true) Initializer called int(1) bool(false)