fix(php): 修复PHP预处理器中的方法重写检查逻辑

- 将参数名称比较从弱类型比较改为严格类型比较
- 修正类、枚举和trait的方法标志位处理逻辑
- 更新抽象方法重写错误消息以更准确反映非抽象类的情况
pull/1/head
韩天峰 3 months ago
parent 68bd54c6c3
commit dec9849c69
  1. 10
      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) {

Loading…
Cancel
Save