mirror of
https://github.com/php/php-src.git
synced 2026-04-23 16:08:35 +02:00
58aa6fc830
RFC: https://wiki.php.net/rfc/lazy-objects Closes GH-15019
48 lines
770 B
PHP
48 lines
770 B
PHP
--TEST--
|
|
Lazy objects: var_export initializes object
|
|
--FILE--
|
|
<?php
|
|
|
|
class C {
|
|
public int $a;
|
|
public function __construct() {
|
|
var_dump(__METHOD__);
|
|
$this->a = 1;
|
|
}
|
|
}
|
|
|
|
$reflector = new ReflectionClass(C::class);
|
|
|
|
print "# Ghost:\n";
|
|
|
|
$obj = $reflector->newLazyGhost(function ($obj) {
|
|
var_dump("initializer");
|
|
$obj->__construct();
|
|
});
|
|
|
|
var_export($obj);
|
|
print "\n";
|
|
|
|
print "# Proxy:\n";
|
|
|
|
$obj = $reflector->newLazyProxy(function ($obj) {
|
|
var_dump("initializer");
|
|
return new C();
|
|
});
|
|
|
|
var_export($obj);
|
|
print "\n";
|
|
--EXPECTF--
|
|
# Ghost:
|
|
string(11) "initializer"
|
|
string(14) "C::__construct"
|
|
\C::__set_state(array(
|
|
'a' => 1,
|
|
))
|
|
# Proxy:
|
|
string(11) "initializer"
|
|
string(14) "C::__construct"
|
|
\C::__set_state(array(
|
|
'a' => 1,
|
|
))
|