@@ -41,11 +41,9 @@ class LazyObjectRegistry
4141 public static array $ classAccessors = [];
4242
4343 /**
44- * @var array<class-string, array{set: bool, isset: bool, unset: bool, clone: bool, serialize: bool, unserialize: bool, sleep: bool, wakeup: bool, destruct: bool, get: int}>
44+ * @var array<class-string, int}>
4545 */
46- public static array $ parentMethods = [];
47-
48- public static ?\Closure $ noInitializerState = null ;
46+ public static array $ parentGet = [];
4947
5048 public static function getClassResetters ($ class )
5149 {
@@ -86,80 +84,16 @@ public static function getClassResetters($class)
8684 return $ resetters ;
8785 }
8886
89- public static function getClassAccessors ($ class )
90- {
91- return \Closure::bind (static fn () => [
92- 'get ' => static function &($ instance , $ name , $ notByRef ) {
93- if (!$ notByRef ) {
94- return $ instance ->$ name ;
95- }
96- $ value = $ instance ->$ name ;
97-
98- return $ value ;
99- },
100- 'set ' => static function ($ instance , $ name , $ value ) {
101- $ instance ->$ name = $ value ;
102- },
103- 'isset ' => static fn ($ instance , $ name ) => isset ($ instance ->$ name ),
104- 'unset ' => static function ($ instance , $ name ) {
105- unset($ instance ->$ name );
106- },
107- ], null , \Closure::class === $ class ? null : $ class )();
108- }
109-
110- public static function getParentMethods ($ class )
87+ public static function getParentGet ($ class ): int
11188 {
11289 $ parent = get_parent_class ($ class );
113- $ methods = [];
114-
115- foreach (['set ' , 'isset ' , 'unset ' , 'clone ' , 'serialize ' , 'unserialize ' , 'sleep ' , 'wakeup ' , 'destruct ' , 'get ' ] as $ method ) {
116- if (!$ parent || !method_exists ($ parent , '__ ' .$ method )) {
117- $ methods [$ method ] = false ;
118- } else {
119- $ m = new \ReflectionMethod ($ parent , '__ ' .$ method );
120- $ methods [$ method ] = !$ m ->isAbstract () && !$ m ->isPrivate ();
121- }
122- }
123-
124- $ methods ['get ' ] = $ methods ['get ' ] ? ($ m ->returnsReference () ? 2 : 1 ) : 0 ;
125-
126- return $ methods ;
127- }
12890
129- public static function getScopeForRead ($ propertyScopes , $ class , $ property )
130- {
131- if (!isset ($ propertyScopes [$ k = "\0$ class \0$ property " ]) && !isset ($ propertyScopes [$ k = "\0* \0$ property " ])) {
132- return null ;
133- }
134- $ frame = debug_backtrace (\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS , 3 )[2 ];
135-
136- if (\ReflectionProperty::class === $ scope = $ frame ['class ' ] ?? \Closure::class) {
137- $ scope = $ frame ['object ' ]->class ;
138- }
139- if ('* ' === $ k [1 ] && ($ class === $ scope || (is_subclass_of ($ class , $ scope ) && !isset ($ propertyScopes ["\0$ scope \0$ property " ])))) {
140- return null ;
141- }
142-
143- return $ scope ;
144- }
145-
146- public static function getScopeForWrite ($ propertyScopes , $ class , $ property , $ flags )
147- {
148- if (!($ flags & (\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_READONLY | \ReflectionProperty::IS_PRIVATE_SET ))) {
149- return null ;
91+ if (!$ parent || !method_exists ($ parent , '__get ' )) {
92+ return 0 ;
15093 }
151- $ frame = debug_backtrace (\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS , 3 )[2 ];
15294
153- if (\ReflectionProperty::class === $ scope = $ frame ['class ' ] ?? \Closure::class) {
154- $ scope = $ frame ['object ' ]->class ;
155- }
156- if ($ flags & (\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PRIVATE_SET )) {
157- return $ scope ;
158- }
159- if ($ flags & (\ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PROTECTED_SET ) && ($ class === $ scope || (is_subclass_of ($ class , $ scope ) && !isset ($ propertyScopes ["\0$ scope \0$ property " ])))) {
160- return null ;
161- }
95+ $ m = new \ReflectionMethod ($ parent , '__get ' );
16296
163- return $ scope ;
97+ return ! $ m -> isAbstract () && ! $ m -> isPrivate () ? ( $ m -> returnsReference () ? 2 : 1 ) : 0 ;
16498 }
16599}
0 commit comments