1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/lazy_objects/init_sets_prop_default_values.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
756 B
PHP

--TEST--
Lazy objects: props are initialized to default values before calling initializer
--FILE--
<?php
class C {
public $a = 1;
public int $b = 2;
public function __construct() {
var_dump(__METHOD__);
$this->a = 3;
$this->b = 4;
}
}
$reflector = new ReflectionClass(C::class);
$obj = $reflector->newLazyGhost(function ($obj) {
var_dump("initializer");
var_dump($obj);
$obj->__construct();
});
var_dump($obj);
var_dump($obj->a);
var_dump($obj);
--EXPECTF--
lazy ghost object(C)#%d (0) {
["b"]=>
uninitialized(int)
}
string(11) "initializer"
object(C)#%d (2) {
["a"]=>
int(1)
["b"]=>
int(2)
}
string(14) "C::__construct"
int(3)
object(C)#%d (2) {
["a"]=>
int(3)
["b"]=>
int(4)
}