fix(php): 解决类方法参数中使用$this的问题并优化静态属性访问

- 添加对类方法中使用$this作为参数名的错误检查
- 修复静态属性被当作动态属性访问时返回null的逻辑
- 在关键词列表中添加this_作为phpx保留关键字
pull/1/head
韩天峰 5 months ago
parent fa6105ebdf
commit 59698b5319
  1. 7
      src/Php/CompilerBase.php
  2. 1
      src/Php/Constants.php

@ -1047,6 +1047,9 @@ class CompilerBase extends \PhpAot\Core\Translator
}
}
$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;
@ -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);
}

@ -54,6 +54,7 @@ class Constants
'template',
'namespace',
'errno', // Linux error code
'this_', // phpx keywords
];
public const UNSUPPORTED_FUNCTIONS = [

Loading…
Cancel
Save