From 59698b53191c8b20ea14acd4fb1b60f660ae379d Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 2 Apr 2026 13:06:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E8=A7=A3=E5=86=B3=E7=B1=BB?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=8F=82=E6=95=B0=E4=B8=AD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?$this=E7=9A=84=E9=97=AE=E9=A2=98=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=9D=99=E6=80=81=E5=B1=9E=E6=80=A7=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加对类方法中使用$this作为参数名的错误检查 - 修复静态属性被当作动态属性访问时返回null的逻辑 - 在关键词列表中添加this_作为phpx保留关键字 --- src/Php/CompilerBase.php | 17 ++++++++++++----- src/Php/Constants.php | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 0d0ea582..d847126e 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1046,14 +1046,17 @@ class CompilerBase extends \PhpAot\Core\Translator $this->fatalError($param, 'Variadic parameters cannot be passed by reference'); } } - $name = $this->parseIdentifier($param->var); - $type = $this->parseParameterType($param, $name); + $name = $this->parseIdentifier($param->var); + if ($this->method and $name == 'this_') { + $this->fatalError($param, 'Cannot use `$this` as parameter of class method'); + } + $type = $this->parseParameterType($param, $name); if ($param->variadic) { - $list[] = self::TYPE_ARRAY . ' ' . $name; + $list[] = self::TYPE_ARRAY . ' ' . $name; } else { - $list[] = $type . ' ' . $name; + $list[] = $type . ' ' . $name; } - $argInfo = new ArgInfo(); + $argInfo = new ArgInfo(); $argInfo->name = $name; $argInfo->type = $type; $argInfo->byRef = $param->byRef; @@ -4005,6 +4008,10 @@ class CompilerBase extends \PhpAot\Core\Translator $classDef = $this->getClass($findClass); if ($classDef->hasProperty($property)) { $propertyDef = $classDef->getProperty($property); + // 属性是静态的,但作为动态属性访问,只能动态获取 + if ($propertyDef->isStatic()) { + return null; + } if ($propertyDef->isPublic()) { return $this->getPropertyOffset($classDef->getNamespacedName(false), $property); } diff --git a/src/Php/Constants.php b/src/Php/Constants.php index f199ca77..5e7fd3ca 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -54,6 +54,7 @@ class Constants 'template', 'namespace', 'errno', // Linux error code + 'this_', // phpx keywords ]; public const UNSUPPORTED_FUNCTIONS = [