@@ -82,6 +82,9 @@ class ClassReflection
8282 /** @var ClassConstantReflection[] */
8383 private array $ constants = [];
8484
85+ /** @var EnumCaseReflection[]|null */
86+ private ?array $ enumCases = null ;
87+
8588 /** @var int[]|null */
8689 private ?array $ classHierarchyDistances = null ;
8790
@@ -752,6 +755,10 @@ public function getEnumCases(): array
752755 throw new ShouldNotHappenException ();
753756 }
754757
758+ if ($ this ->enumCases !== null ) {
759+ return $ this ->enumCases ;
760+ }
761+
755762 $ cases = [];
756763 $ initializerExprContext = InitializerExprContext::fromClassReflection ($ this );
757764 foreach ($ this ->reflection ->getCases () as $ case ) {
@@ -764,7 +771,7 @@ public function getEnumCases(): array
764771 $ cases [$ caseName ] = new EnumCaseReflection ($ this , $ caseName , $ valueType );
765772 }
766773
767- return $ cases ;
774+ return $ this -> enumCases = $ cases ;
768775 }
769776
770777 public function getEnumCase (string $ name ): EnumCaseReflection
@@ -777,6 +784,10 @@ public function getEnumCase(string $name): EnumCaseReflection
777784 throw new ShouldNotHappenException ();
778785 }
779786
787+ if ($ this ->enumCases !== null && array_key_exists ($ name , $ this ->enumCases )) {
788+ return $ this ->enumCases [$ name ];
789+ }
790+
780791 $ case = $ this ->reflection ->getCase ($ name );
781792 $ valueType = null ;
782793 if ($ case instanceof ReflectionEnumBackedCase) {
0 commit comments