1
0
mirror of https://github.com/php/php-src.git synced 2026-04-23 16:08:35 +02:00
Files
archived-php-src/Zend/tests/lazy_objects/init_trigger_var_export.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

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,
))