From dec9849c69db787a746d310eb3b6d9828c60b315 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 10 Jun 2026 14:54:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8DPHP=E9=A2=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=99=A8=E4=B8=AD=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E9=87=8D=E5=86=99=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 - 将参数名称比较从弱类型比较改为严格类型比较 - 修正类、枚举和trait的方法标志位处理逻辑 - 更新抽象方法重写错误消息以更准确反映非抽象类的情况 --- src/Php/Preprocessor.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index 64821370..f2725fd6 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -266,7 +266,7 @@ class Preprocessor extends CompilerBase } } $name = $this->parseIdentifier($param->var); - if ($this->method and $name == 'this_') { + if ($this->method and $name === 'this_') { $this->fatalError($param, 'Cannot use `$this` as parameter of class method'); } $argInfo = new ArgInfo(); @@ -411,9 +411,7 @@ class Preprocessor extends CompilerBase $fullClassName = $this->getFullClassName(); $fullClassNameLower = strtolower($fullClassName); - if ($class instanceof Node\Stmt\Enum_) { - $flags = Modifiers::PUBLIC; - } elseif (!$class instanceof Node\Stmt\Trait_) { + if ($class instanceof Node\Stmt\Class_) { $flags = $class->flags; } else { $flags = Modifiers::PUBLIC; @@ -591,8 +589,8 @@ class Preprocessor extends CompilerBase $this->checkRequiredArgNum($name, $this->methodDef, $v); $this->classDef->addMethod($this->methodDef); } else { - if (isset($class->flags) and !($class->flags & Modifiers::ABSTRACT)) { - $this->fatalError($v, "Class {$this->class} cannot override non-abstract method {$v->name}"); + if (!$class instanceof Node\Stmt\Trait_ && isset($class->flags) && !($class->flags & Modifiers::ABSTRACT)) { + $this->fatalError($v, "Non-abstract class {$this->class} contains abstract method {$v->name}"); } if ($this->method === '__construct') { foreach ($v->params as $param) {