@@ -177,6 +177,7 @@ public function __construct(
177177 private SignatureMapProvider $ signatureMapProvider ,
178178 private DeprecationProvider $ deprecationProvider ,
179179 private AttributeReflectionFactory $ attributeReflectionFactory ,
180+ private PhpClassReflectionExtension $ phpClassReflectionExtension ,
180181 private array $ propertiesClassReflectionExtensions ,
181182 private array $ methodsClassReflectionExtensions ,
182183 private array $ allowedSubTypesClassReflectionExtensions ,
@@ -474,18 +475,16 @@ public function hasProperty(string $propertyName): bool
474475 return $ this ->hasPropertyCache [$ propertyName ] = $ this ->hasNativeProperty ($ propertyName );
475476 }
476477
477- foreach ($ this ->propertiesClassReflectionExtensions as $ i => $ extension ) {
478- if ($ i > 0 && !$ this ->allowsDynamicProperties ()) {
479- break ;
480- }
481- if ($ extension ->hasProperty ($ this , $ propertyName )) {
482- return $ this ->hasPropertyCache [$ propertyName ] = true ;
483- }
478+ if ($ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
479+ return $ this ->hasPropertyCache [$ propertyName ] = true ;
484480 }
485481
486- // For BC purpose
487- if ($ this ->getPhpExtension ()->hasProperty ($ this , $ propertyName )) {
488- return $ this ->hasPropertyCache [$ propertyName ] = true ;
482+ if ($ this ->allowsDynamicProperties ()) {
483+ foreach ($ this ->propertiesClassReflectionExtensions as $ extension ) {
484+ if ($ extension ->hasProperty ($ this , $ propertyName )) {
485+ return $ this ->hasPropertyCache [$ propertyName ] = true ;
486+ }
487+ }
489488 }
490489
491490 if ($ this ->requireExtendsPropertiesClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
@@ -505,16 +504,22 @@ public function hasInstanceProperty(string $propertyName): bool
505504 return $ this ->hasInstancePropertyCache [$ propertyName ] = $ this ->hasNativeProperty ($ propertyName );
506505 }
507506
508- foreach ($ this ->propertiesClassReflectionExtensions as $ i => $ extension ) {
509- if ($ i > 0 && !$ this ->allowsDynamicProperties ()) {
510- break ;
507+ if ($ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
508+ $ property = $ this ->phpClassReflectionExtension ->getProperty ($ this , $ propertyName );
509+ if (!$ property ->isStatic ()) {
510+ return $ this ->hasInstancePropertyCache [$ propertyName ] = true ;
511511 }
512- if ($ extension ->hasProperty ($ this , $ propertyName )) {
513- $ property = $ extension ->getProperty ($ this , $ propertyName );
514- if ($ property ->isStatic ()) {
515- continue ;
512+ }
513+
514+ if ($ this ->allowsDynamicProperties ()) {
515+ foreach ($ this ->propertiesClassReflectionExtensions as $ extension ) {
516+ if ($ extension ->hasProperty ($ this , $ propertyName )) {
517+ $ property = $ extension ->getProperty ($ this , $ propertyName );
518+ if ($ property ->isStatic ()) {
519+ continue ;
520+ }
521+ return $ this ->hasInstancePropertyCache [$ propertyName ] = true ;
516522 }
517- return $ this ->hasInstancePropertyCache [$ propertyName ] = true ;
518523 }
519524 }
520525
@@ -531,8 +536,8 @@ public function hasStaticProperty(string $propertyName): bool
531536 return $ this ->hasStaticPropertyCache [$ propertyName ];
532537 }
533538
534- if ($ this ->getPhpExtension () ->hasProperty ($ this , $ propertyName )) {
535- $ property = $ this ->getPhpExtension () ->getProperty ($ this , $ propertyName );
539+ if ($ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
540+ $ property = $ this ->phpClassReflectionExtension ->getProperty ($ this , $ propertyName );
536541 if ($ property ->isStatic ()) {
537542 return $ this ->hasStaticPropertyCache [$ propertyName ] = true ;
538543 }
@@ -551,6 +556,10 @@ public function hasMethod(string $methodName): bool
551556 return $ this ->hasMethodCache [$ methodName ];
552557 }
553558
559+ if ($ this ->phpClassReflectionExtension ->hasMethod ($ this , $ methodName )) {
560+ return $ this ->hasMethodCache [$ methodName ] = true ;
561+ }
562+
554563 foreach ($ this ->methodsClassReflectionExtensions as $ extension ) {
555564 if ($ extension ->hasMethod ($ this , $ methodName )) {
556565 return $ this ->hasMethodCache [$ methodName ] = true ;
@@ -571,6 +580,14 @@ public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope):
571580 $ key = sprintf ('%s-%s ' , $ key , $ scope ->getClassReflection ()->getCacheKey ());
572581 }
573582
583+ if ($ this ->phpClassReflectionExtension ->hasMethod ($ this , $ methodName )) {
584+ $ method = $ this ->phpClassReflectionExtension ->getMethod ($ this , $ methodName );
585+ if ($ scope ->canCallMethod ($ method )) {
586+ return $ this ->methods [$ key ] = $ method ;
587+ }
588+ $ this ->methods [$ key ] = $ method ;
589+ }
590+
574591 if (!isset ($ this ->methods [$ key ])) {
575592 foreach ($ this ->methodsClassReflectionExtensions as $ extension ) {
576593 if (!$ extension ->hasMethod ($ this , $ methodName )) {
@@ -619,15 +636,15 @@ private function wrapExtendedProperty(string $propertyName, PropertyReflection $
619636
620637 public function hasNativeMethod (string $ methodName ): bool
621638 {
622- return $ this ->getPhpExtension () ->hasNativeMethod ($ this , $ methodName );
639+ return $ this ->phpClassReflectionExtension ->hasNativeMethod ($ this , $ methodName );
623640 }
624641
625642 public function getNativeMethod (string $ methodName ): ExtendedMethodReflection
626643 {
627644 if (!$ this ->hasNativeMethod ($ methodName )) {
628645 throw new MissingMethodFromReflectionException ($ this ->getName (), $ methodName );
629646 }
630- return $ this ->getPhpExtension () ->getNativeMethod ($ this , $ methodName );
647+ return $ this ->phpClassReflectionExtension ->getNativeMethod ($ this , $ methodName );
631648 }
632649
633650 public function hasConstructor (): bool
@@ -662,16 +679,6 @@ private function findConstructor(): ?ReflectionMethod
662679 return $ constructor ;
663680 }
664681
665- private function getPhpExtension (): PhpClassReflectionExtension
666- {
667- $ extension = $ this ->methodsClassReflectionExtensions [0 ];
668- if (!$ extension instanceof PhpClassReflectionExtension) {
669- throw new ShouldNotHappenException ();
670- }
671-
672- return $ extension ;
673- }
674-
675682 /** @internal */
676683 public function evictPrivateSymbols (): void
677684 {
@@ -710,7 +717,7 @@ public function evictPrivateSymbols(): void
710717
711718 unset($ this ->methods [$ name ]);
712719 }
713- $ this ->getPhpExtension () ->evictPrivateSymbols ($ this ->getCacheKey ());
720+ $ this ->phpClassReflectionExtension ->evictPrivateSymbols ($ this ->getCacheKey ());
714721 }
715722
716723 /** @deprecated Use getInstanceProperty or getStaticProperty */
@@ -725,12 +732,16 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
725732 $ key = sprintf ('%s-%s ' , $ key , $ scope ->getClassReflection ()->getCacheKey ());
726733 }
727734
728- if (!isset ($ this ->properties [$ key ])) {
729- foreach ($ this ->propertiesClassReflectionExtensions as $ i => $ extension ) {
730- if ($ i > 0 && !$ this ->allowsDynamicProperties ()) {
731- break ;
732- }
735+ if ($ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
736+ $ property = $ this ->phpClassReflectionExtension ->getProperty ($ this , $ propertyName );
737+ if ($ scope ->canReadProperty ($ property )) {
738+ return $ this ->properties [$ key ] = $ property ;
739+ }
740+ $ this ->properties [$ key ] = $ property ;
741+ }
733742
743+ if (!isset ($ this ->properties [$ key ]) && $ this ->allowsDynamicProperties ()) {
744+ foreach ($ this ->propertiesClassReflectionExtensions as $ extension ) {
734745 if (!$ extension ->hasProperty ($ this , $ propertyName )) {
735746 continue ;
736747 }
@@ -744,8 +755,8 @@ public function getProperty(string $propertyName, ClassMemberAccessAnswerer $sco
744755 }
745756
746757 // For BC purpose
747- if ($ this ->getPhpExtension () ->hasProperty ($ this , $ propertyName )) {
748- $ property = $ this ->getPhpExtension () ->getProperty ($ this , $ propertyName );
758+ if ($ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
759+ $ property = $ this ->phpClassReflectionExtension ->getProperty ($ this , $ propertyName );
749760
750761 return $ this ->properties [$ key ] = $ property ;
751762 }
@@ -775,12 +786,18 @@ public function getInstanceProperty(string $propertyName, ClassMemberAccessAnswe
775786 $ key = sprintf ('%s-%s ' , $ key , $ scope ->getClassReflection ()->getCacheKey ());
776787 }
777788
778- if (!isset ($ this ->instanceProperties [$ key ])) {
779- foreach ($ this ->propertiesClassReflectionExtensions as $ i => $ extension ) {
780- if ($ i > 0 && !$ this ->allowsDynamicProperties ()) {
781- break ;
789+ if ($ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
790+ $ property = $ this ->phpClassReflectionExtension ->getProperty ($ this , $ propertyName );
791+ if (!$ property ->isStatic ()) {
792+ if ($ scope ->canReadProperty ($ property )) {
793+ return $ this ->instanceProperties [$ key ] = $ property ;
782794 }
795+ $ this ->instanceProperties [$ key ] = $ property ;
796+ }
797+ }
783798
799+ if (!isset ($ this ->instanceProperties [$ key ]) && $ this ->allowsDynamicProperties ()) {
800+ foreach ($ this ->propertiesClassReflectionExtensions as $ extension ) {
784801 if (!$ extension ->hasProperty ($ this , $ propertyName )) {
785802 continue ;
786803 }
@@ -819,8 +836,8 @@ public function getStaticProperty(string $propertyName): ExtendedPropertyReflect
819836 return $ this ->staticProperties [$ key ];
820837 }
821838
822- if ($ this ->getPhpExtension () ->hasProperty ($ this , $ propertyName )) {
823- $ nakedProperty = $ this ->getPhpExtension () ->getProperty ($ this , $ propertyName );
839+ if ($ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName )) {
840+ $ nakedProperty = $ this ->phpClassReflectionExtension ->getProperty ($ this , $ propertyName );
824841 if ($ nakedProperty ->isStatic ()) {
825842 $ property = $ this ->wrapExtendedProperty ($ propertyName , $ nakedProperty );
826843 if ($ property ->isStatic ()) {
@@ -839,7 +856,7 @@ public function getStaticProperty(string $propertyName): ExtendedPropertyReflect
839856
840857 public function hasNativeProperty (string $ propertyName ): bool
841858 {
842- return $ this ->getPhpExtension () ->hasProperty ($ this , $ propertyName );
859+ return $ this ->phpClassReflectionExtension ->hasProperty ($ this , $ propertyName );
843860 }
844861
845862 public function getNativeProperty (string $ propertyName ): PhpPropertyReflection
@@ -848,7 +865,7 @@ public function getNativeProperty(string $propertyName): PhpPropertyReflection
848865 throw new MissingPropertyFromReflectionException ($ this ->getName (), $ propertyName );
849866 }
850867
851- return $ this ->getPhpExtension () ->getNativeProperty ($ this , $ propertyName );
868+ return $ this ->phpClassReflectionExtension ->getNativeProperty ($ this , $ propertyName );
852869 }
853870
854871 public function isAbstract (): bool
@@ -1762,6 +1779,7 @@ public function withTypes(array $types): self
17621779 $ this ->signatureMapProvider ,
17631780 $ this ->deprecationProvider ,
17641781 $ this ->attributeReflectionFactory ,
1782+ $ this ->phpClassReflectionExtension ,
17651783 $ this ->propertiesClassReflectionExtensions ,
17661784 $ this ->methodsClassReflectionExtensions ,
17671785 $ this ->allowedSubTypesClassReflectionExtensions ,
@@ -1794,6 +1812,7 @@ public function withVariances(array $variances): self
17941812 $ this ->signatureMapProvider ,
17951813 $ this ->deprecationProvider ,
17961814 $ this ->attributeReflectionFactory ,
1815+ $ this ->phpClassReflectionExtension ,
17971816 $ this ->propertiesClassReflectionExtensions ,
17981817 $ this ->methodsClassReflectionExtensions ,
17991818 $ this ->allowedSubTypesClassReflectionExtensions ,
@@ -1836,6 +1855,7 @@ public function asFinal(): self
18361855 $ this ->signatureMapProvider ,
18371856 $ this ->deprecationProvider ,
18381857 $ this ->attributeReflectionFactory ,
1858+ $ this ->phpClassReflectionExtension ,
18391859 $ this ->propertiesClassReflectionExtensions ,
18401860 $ this ->methodsClassReflectionExtensions ,
18411861 $ this ->allowedSubTypesClassReflectionExtensions ,
@@ -1878,6 +1898,7 @@ public function removeFinalKeywordOverride(): self
18781898 $ this ->signatureMapProvider ,
18791899 $ this ->deprecationProvider ,
18801900 $ this ->attributeReflectionFactory ,
1901+ $ this ->phpClassReflectionExtension ,
18811902 $ this ->propertiesClassReflectionExtensions ,
18821903 $ this ->methodsClassReflectionExtensions ,
18831904 $ this ->allowedSubTypesClassReflectionExtensions ,
0 commit comments