diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 93e5816a73..f374870b1b 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -2484,7 +2484,8 @@ public function resolveName(Name $name): string { $originalClass = (string) $name; if ($this->isInClass()) { - if (in_array(strtolower($originalClass), [ + $lowerClass = strtolower($originalClass); + if (in_array($lowerClass, [ 'self', 'static', ], true)) { @@ -2492,7 +2493,7 @@ public function resolveName(Name $name): string return $this->inClosureBindScopeClasses[0]; } return $this->getClassReflection()->getName(); - } elseif ($originalClass === 'parent') { + } elseif ($lowerClass === 'parent') { $currentClassReflection = $this->getClassReflection(); if ($currentClassReflection->getParentClass() !== null) { return $currentClassReflection->getParentClass()->getName(); diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index b8615874f2..e5a6e58aed 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -1791,7 +1791,7 @@ public function getClassConstFetchTypeByReflection(Name|Expr $class, string $con } if (in_array(strtolower($constantClass), $namesToResolve, true)) { $resolvedName = $this->resolveName($class, $classReflection); - if ($resolvedName === 'parent' && strtolower($constantName) === 'class') { + if (strtolower($resolvedName) === 'parent' && strtolower($constantName) === 'class') { return new ClassStringType(); } $constantClassType = $this->resolveTypeByName($class, $classReflection); @@ -2024,12 +2024,14 @@ private function resolveName(Name $name, ?ClassReflection $classReflection): str { $originalClass = (string) $name; if ($classReflection !== null) { - if (in_array(strtolower($originalClass), [ + $lowerClass = strtolower($originalClass); + + if (in_array($lowerClass, [ 'self', 'static', ], true)) { return $classReflection->getName(); - } elseif ($originalClass === 'parent') { + } elseif ($lowerClass === 'parent') { if ($classReflection->getParentClass() !== null) { return $classReflection->getParentClass()->getName(); } diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index a5f1c378b1..d767e310de 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1478,6 +1478,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10834.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10952.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10952b.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/case-insensitive-parent.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10893.php'); } diff --git a/tests/PHPStan/Analyser/data/case-insensitive-parent.php b/tests/PHPStan/Analyser/data/case-insensitive-parent.php new file mode 100644 index 0000000000..a1eb8830a3 --- /dev/null +++ b/tests/PHPStan/Analyser/data/case-insensitive-parent.php @@ -0,0 +1,35 @@ +