@@ -19,6 +19,7 @@ final class ClassReflector implements Reflector
1919 private array $ memoize = [];
2020
2121 private readonly PHPReflectionClass $ reflectionClass ;
22+ private string $ name ;
2223
2324 /**
2425 * @param class-string<TClassName>|TClassName|PHPReflectionClass<TClassName> $reflectionClass
@@ -34,6 +35,7 @@ public function __construct(string|object $reflectionClass)
3435 }
3536
3637 $ this ->reflectionClass = $ reflectionClass ;
38+ $ this ->name = $ reflectionClass ->getName ();
3739 }
3840
3941 public function getReflection (): PHPReflectionClass
@@ -104,7 +106,7 @@ public function hasProperty(string $name): bool
104106 */
105107 public function getName (): string
106108 {
107- return $ this ->reflectionClass -> getName () ;
109+ return $ this ->name ;
108110 }
109111
110112 public function getShortName (): string
@@ -162,12 +164,12 @@ public function callStatic(string $method, mixed ...$args): mixed
162164
163165 public function is (string $ className ): bool
164166 {
165- return $ this ->getType ()-> matches ( $ className );
167+ return is_a ( $ this ->getName (), $ className, allow_string: true );
166168 }
167169
168170 public function implements (string $ interface ): bool
169171 {
170- return $ this ->isInstantiable () && $ this ->getType ()-> matches ( $ interface );
172+ return $ this ->isInstantiable () && is_a ( $ this ->getName (), $ interface, allow_string: true );
171173 }
172174
173175 private function memoize (string $ key , Closure $ closure ): mixed
@@ -187,5 +189,6 @@ public function __serialize(): array
187189 public function __unserialize (array $ data ): void
188190 {
189191 $ this ->reflectionClass = new PHPReflectionClass ($ data ['name ' ]);
192+ $ this ->name = $ data ['name ' ];
190193 }
191194}
0 commit comments