Whats new in PHP 8.4
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
php84/LazyGhost.php

20 lines
468 B

<?php
class Example {
public function __construct(public int $data) {
echo __METHOD__, "\n";
}
}
$initializer = static function (Example $ghost): void {
// Initialize
$ghost->__construct(1);
};
$reflector = new ReflectionClass(Example::class);
$object = $reflector->newLazyGhost($initializer);
var_dump($object);
var_dump($object instanceof Example);
// Triggers initialization, and fetches the property after that
var_dump($object->data);