From f2e063b41d7f841789b78bc3681f25225d5ac78a Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 17 Jun 2026 13:34:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E5=86=85=E7=B1=BB=E5=90=8D=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=8F=8Ause=E5=88=AB=E5=90=8D=E6=9F=A5=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/CompilerBase.php | 11 +++-- tests/aot/namespace/ns-same-as-class.phpt | 52 +++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 tests/aot/namespace/ns-same-as-class.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 0172422f..91c678e4 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -4732,8 +4732,10 @@ class CompilerBase extends \PhpAot\Core\Translator $this->fatalError($expr, 'Cannot access parent:: when current class does not extend any class'); } $class = $this->classDef->extends; + } else { + $class = $this->getNamespacedClassName($class); } - $nativeProperty = $this->findNativeProperty($expr, $propertyName, $class, $this->namespace, true); + $nativeProperty = $this->findNativeProperty($expr, $propertyName, $class, true); if ($nativeProperty) { $expr->setAttribute('nativeProperty', $nativeProperty); return $nativeProperty; @@ -4745,13 +4747,10 @@ class CompilerBase extends \PhpAot\Core\Translator /** * @param NodeAbstract $expr 仅用于输出错误日志 */ - protected function findNativeProperty(NodeAbstract $expr, string $property, string $class, string $namespace = '', bool $static = false): ?string + protected function findNativeProperty(NodeAbstract $expr, string $property, string $class, bool $static = false): ?string { $findClass = $class; - if ($namespace) { - $findClass = $namespace . '\\' . $class; - } - $scope = $this->class ? ltrim($namespace . '\\' . $class, '\\') : ''; + $scope = $this->class ? $class : ''; $propertyDef = null; $classDef = null; while (true) { diff --git a/tests/aot/namespace/ns-same-as-class.phpt b/tests/aot/namespace/ns-same-as-class.phpt new file mode 100644 index 00000000..9e2fbd7b --- /dev/null +++ b/tests/aot/namespace/ns-same-as-class.phpt @@ -0,0 +1,52 @@ +--TEST-- +use class A\B (without alias) inside namespace A\B, call B::$v +--FILE-- + +--EXPECT-- +int(123) +int(123) +int(123) +int(123)