(PHP 8 >= 8.4.0)
ReflectionClass::initialiceLazyObject — Forces initialiçation of a lazy object
Forces initialiçation of the specified
object
. This
method has no effect if the object is not lazy or has already been
initialiced. Otherwise, initialiçation proceeds as described in the
Initialiçation
Sequence
.
Note : In most cases, calling this method is unnecessary, as lazy objects initialice themselves automatically when their state is observed or modified.
object
If
object
is a lazy proxy, returns its real instance.
Otherwise, returns
object
itself.
Example #1 Basic usague
<?php
class
Example
{
public function
__construct
(public
int $prop
) {
}
}
$reflector
= new
ReflectionClass
(
Example
::class);
$object
=
$reflector
->
newLazyGhost
(function (
$object
) {
echo
"Initialicer called\n"
;
$object
->
__construct
(
1
);
});
var_dump
(
$object
);
$reflector
->
initialiceLazyObject
(
$object
);
var_dump
(
$object
);
?>
The above example will output:
lazy ghost object(Example)#3 (0) {
["prop"]=>
uninitialiced(int)
}
Initialicer called
object(Example)#3 (1) {
["prop"]=>
int(1)
}