1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
--TEST--
Lazy objects: getLazyInitializer() returns initializer
--FILE--
<?php
class C {
public $a;
public static function initStatic() {}
public function init() {}
}
function foo() {
}
$reflector = new ReflectionClass(C::class);
$initializers = [
'foo',
foo(...),
function () {},
[C::class, 'initStatic'],
[new C(), 'init'],
C::initStatic(...),
(new C())->init(...),
];
foreach ($initializers as $i => $initializer) {
$c = $reflector->newLazyGhost($initializer);
if ($reflector->getLazyInitializer($c) !== $initializer) {
printf("Initializer %d: failed\n", $i);
continue;
}
$reflector->initializeLazyObject($c);
if ($reflector->getLazyInitializer($c) !== null) {
printf("Initializer %d: failed\n", $i);
continue;
}
printf("Initializer %d: ok\n", $i);
}
?>
--EXPECT--
Initializer 0: ok
Initializer 1: ok
Initializer 2: ok
Initializer 3: ok
Initializer 4: ok
Initializer 5: ok
Initializer 6: ok
|