From 0af331db16ba7a2db211eb3e7faaf50e206210e6 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 1 Jul 2026 10:50:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E9=87=8D=E6=9E=84=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E6=AF=94=E8=BE=83=E5=92=8C=E5=B1=9E=E6=80=A7=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=A3=80=E6=9F=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除对 PropertyAccessResolver 的依赖,直接实现类名比较功能 - 使用 strcasecmp 函数进行大小写不敏感的类名比较 - 重写 isSameOrSubclassOf 方法,通过 getParentClass 遍历继承链 - 简化 canAccessProtectedProperty 逻辑,优化作用域检查条件 - 更新单元测试中的属性访问器解析方法调用方式 --- phpunit/src/CompilerPhaseTest.php | 4 +++- src/Php/CompilerBase.php | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) 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