| 
 | 1 | +--TEST--  | 
 | 2 | +Lazy Objects: ReflectionProperty::isLazy()  | 
 | 3 | +--FILE--  | 
 | 4 | +<?php  | 
 | 5 | + | 
 | 6 | +#[AllowDynamicProperties]  | 
 | 7 | +class C {  | 
 | 8 | +    public static $staticProp;  | 
 | 9 | +    public int $typed;  | 
 | 10 | +    public $untyped;  | 
 | 11 | +    public $virtual {  | 
 | 12 | +        get {}  | 
 | 13 | +    }  | 
 | 14 | +}  | 
 | 15 | + | 
 | 16 | +function testProps(ReflectionClass $reflector, object $obj) {  | 
 | 17 | +    foreach (['staticProp', 'typed', 'untyped', 'virtual', 'dynamic'] as $name) {  | 
 | 18 | +        if ('dynamic' === $name) {  | 
 | 19 | +            $tmp = new C();  | 
 | 20 | +            $tmp->dynamic = 1;  | 
 | 21 | +            $pr = new ReflectionProperty($tmp, $name);  | 
 | 22 | +        } else {  | 
 | 23 | +            $pr = $reflector->getProperty($name);  | 
 | 24 | +        }  | 
 | 25 | +        printf("%s: %d\n", $name, $pr->isLazy($obj));  | 
 | 26 | +    }  | 
 | 27 | +}  | 
 | 28 | + | 
 | 29 | +$reflector = new ReflectionClass(C::class);  | 
 | 30 | + | 
 | 31 | +print "# Ghost\n";  | 
 | 32 | + | 
 | 33 | +$obj = $reflector->newLazyGhost(function () { });  | 
 | 34 | + | 
 | 35 | +testProps($reflector, $obj);  | 
 | 36 | + | 
 | 37 | +$pr = $reflector->getProperty('typed');  | 
 | 38 | +$pr->skipLazyInitialization($obj);  | 
 | 39 | +printf("typed (skipped): %d\n", $pr->isLazy($obj));  | 
 | 40 | + | 
 | 41 | +print "# Initialized Ghost\n";  | 
 | 42 | + | 
 | 43 | +$reflector->initializeLazyObject($obj);  | 
 | 44 | + | 
 | 45 | +testProps($reflector, $obj);  | 
 | 46 | + | 
 | 47 | +print "# Proxy\n";  | 
 | 48 | + | 
 | 49 | +$obj = $reflector->newLazyProxy(function () {  | 
 | 50 | +    return new C();  | 
 | 51 | +});  | 
 | 52 | + | 
 | 53 | +testProps($reflector, $obj);  | 
 | 54 | + | 
 | 55 | +$pr = $reflector->getProperty('typed');  | 
 | 56 | +$pr->skipLazyInitialization($obj);  | 
 | 57 | +printf("typed (skipped prop): %d\n", $pr->isLazy($obj));  | 
 | 58 | + | 
 | 59 | +print "# Initialized Proxy\n";  | 
 | 60 | + | 
 | 61 | +$reflector->initializeLazyObject($obj);  | 
 | 62 | + | 
 | 63 | +testProps($reflector, $obj);  | 
 | 64 | + | 
 | 65 | +print "# Nested Proxy\n";  | 
 | 66 | + | 
 | 67 | +$nested = new C();  | 
 | 68 | +$obj = $reflector->newLazyProxy(function () use ($nested) {  | 
 | 69 | +    return $nested;  | 
 | 70 | +});  | 
 | 71 | +$reflector->initializeLazyObject($obj);  | 
 | 72 | +$reflector->resetAsLazyProxy($nested, function () {  | 
 | 73 | +    return new C();  | 
 | 74 | +});  | 
 | 75 | + | 
 | 76 | +testProps($reflector, $obj);  | 
 | 77 | + | 
 | 78 | +print "# Nested Proxy (nested initialized)\n";  | 
 | 79 | + | 
 | 80 | +$nested = new C();  | 
 | 81 | +$obj = $reflector->newLazyProxy(function () use ($nested) {  | 
 | 82 | +    return $nested;  | 
 | 83 | +});  | 
 | 84 | +$reflector->initializeLazyObject($obj);  | 
 | 85 | +$reflector->resetAsLazyProxy($nested, function () {  | 
 | 86 | +    return new C();  | 
 | 87 | +});  | 
 | 88 | +$reflector->initializeLazyObject($nested);  | 
 | 89 | + | 
 | 90 | +testProps($reflector, $obj);  | 
 | 91 | + | 
 | 92 | +print "# Internal\n";  | 
 | 93 | + | 
 | 94 | +$obj = (new DateTime())->diff(new DateTime());  | 
 | 95 | +$reflector = new ReflectionClass(DateInterval::class);  | 
 | 96 | +$pr = new ReflectionProperty($obj, 'y');  | 
 | 97 | +printf("y: %d\n", $pr->isLazy($obj));  | 
 | 98 | + | 
 | 99 | +?>  | 
 | 100 | +--EXPECT--  | 
 | 101 | +# Ghost  | 
 | 102 | +staticProp: 0  | 
 | 103 | +typed: 1  | 
 | 104 | +untyped: 1  | 
 | 105 | +virtual: 0  | 
 | 106 | +dynamic: 0  | 
 | 107 | +typed (skipped): 0  | 
 | 108 | +# Initialized Ghost  | 
 | 109 | +staticProp: 0  | 
 | 110 | +typed: 0  | 
 | 111 | +untyped: 0  | 
 | 112 | +virtual: 0  | 
 | 113 | +dynamic: 0  | 
 | 114 | +# Proxy  | 
 | 115 | +staticProp: 0  | 
 | 116 | +typed: 1  | 
 | 117 | +untyped: 1  | 
 | 118 | +virtual: 0  | 
 | 119 | +dynamic: 0  | 
 | 120 | +typed (skipped prop): 0  | 
 | 121 | +# Initialized Proxy  | 
 | 122 | +staticProp: 0  | 
 | 123 | +typed: 0  | 
 | 124 | +untyped: 0  | 
 | 125 | +virtual: 0  | 
 | 126 | +dynamic: 0  | 
 | 127 | +# Nested Proxy  | 
 | 128 | +staticProp: 0  | 
 | 129 | +typed: 1  | 
 | 130 | +untyped: 1  | 
 | 131 | +virtual: 0  | 
 | 132 | +dynamic: 0  | 
 | 133 | +# Nested Proxy (nested initialized)  | 
 | 134 | +staticProp: 0  | 
 | 135 | +typed: 0  | 
 | 136 | +untyped: 0  | 
 | 137 | +virtual: 0  | 
 | 138 | +dynamic: 0  | 
 | 139 | +# Internal  | 
 | 140 | +y: 0  | 
0 commit comments