mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
69 lines
1.1 KiB
PHP
69 lines
1.1 KiB
PHP
--TEST--
|
|
Lazy objects: JIT: ASSIGN_OBJ with known prop_info
|
|
--FILE--
|
|
<?php
|
|
|
|
class C {
|
|
public $a;
|
|
public int $b = 1;
|
|
|
|
public function __construct() {
|
|
var_dump(__METHOD__);
|
|
$this->b = 3;
|
|
}
|
|
}
|
|
|
|
function test(string $name, object $obj) {
|
|
printf("# %s:\n", $name);
|
|
|
|
var_dump($obj);
|
|
$obj->a = 2;
|
|
var_dump($obj);
|
|
}
|
|
|
|
$reflector = new ReflectionClass(C::class);
|
|
|
|
$obj = $reflector->newLazyGhost(function ($obj) {
|
|
var_dump("initializer");
|
|
$obj->__construct();
|
|
});
|
|
|
|
test('Ghost', $obj);
|
|
|
|
$obj = $reflector->newLazyProxy(function ($obj) {
|
|
var_dump("initializer");
|
|
return new C();
|
|
});
|
|
|
|
test('Proxy', $obj);
|
|
|
|
--EXPECTF--
|
|
# Ghost:
|
|
lazy ghost object(C)#%d (0) {
|
|
["b"]=>
|
|
uninitialized(int)
|
|
}
|
|
string(11) "initializer"
|
|
string(14) "C::__construct"
|
|
object(C)#%d (2) {
|
|
["a"]=>
|
|
int(2)
|
|
["b"]=>
|
|
int(3)
|
|
}
|
|
# Proxy:
|
|
lazy proxy object(C)#%d (0) {
|
|
["b"]=>
|
|
uninitialized(int)
|
|
}
|
|
string(11) "initializer"
|
|
string(14) "C::__construct"
|
|
lazy proxy object(C)#%d (1) {
|
|
["instance"]=>
|
|
object(C)#%d (2) {
|
|
["a"]=>
|
|
int(2)
|
|
["b"]=>
|
|
int(3)
|
|
}
|
|
}
|