diff --git a/phpunit/src/CompilerPhaseTest.php b/phpunit/src/CompilerPhaseTest.php index b767aa61..5aac906c 100644 --- a/phpunit/src/CompilerPhaseTest.php +++ b/phpunit/src/CompilerPhaseTest.php @@ -24,7 +24,9 @@ class CompilerPhaseProbe extends CompilerTest public function probePropertyAccessResolver(): bool { - return $this->canAccessProtectedProperty('ProbeClass', 'ProbeClass'); + $method = new ReflectionMethod(\PhpAot\Php\CompilerBase::class, 'createPropertyAccessResolver'); + $resolver = $method->invoke($this); + return $resolver->canAccessProtectedProperty('ProbeClass', 'ProbeClass'); } } diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index f7c5afcb..05595d5f 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -5937,17 +5937,29 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont protected function isSameClassName(string $classA, string $classB): bool { - return $this->createPropertyAccessResolver()->isSameClassName($classA, $classB); + return strcasecmp(ltrim($classA, '\\'), ltrim($classB, '\\')) === 0; } protected function isSameOrSubclassOf(string $class, string $parent): bool { - return $this->createPropertyAccessResolver()->isSameOrSubclassOf($class, $parent); + $class = strtolower(ltrim($class, '\\')); + $parent = strtolower(ltrim($parent, '\\')); + while ($class !== '') { + if ($class === $parent) { + return true; + } + $class = $this->getParentClass($class); + } + return false; } protected function canAccessProtectedProperty(string $scope, string $declaringClass): bool { - return $this->createPropertyAccessResolver()->canAccessProtectedProperty($scope, $declaringClass); + if ($scope === '') { + return false; + } + return $this->isSameOrSubclassOf($scope, $declaringClass) + || $this->isSameOrSubclassOf($declaringClass, $scope); } private function resolveNativeInstanceProperty(NodeAbstract $expr, string $property, string $class): ?PropertyAccessResult