feat(php): 添加对 self 类型的支持

- 在 CompilerBase.php 中添加了对 self 类型的处理逻辑
- 将 self 类型的对象添加到对象映射中
- 添加了静态类属性读写测试用例
- 测试验证了 self 类型在静态上下文中的正确行为
pull/1/head
韩天峰 6 months ago
parent eed45fdb61
commit afc4ef87f8
  1. 3
      src/Php/CompilerBase.php
  2. 21
      tests/aot/static_prop_write_2.phpt

@ -1744,6 +1744,9 @@ class CompilerBase extends \PhpAot\Core\Translator
// no break
case 'mixed':
return self::TYPE_VAR;
case 'self':
$this->objects[$var] = $this->classDef->getNamespacedName(false);
return self::TYPE_OBJECT;
case 'resource':
$this->fatalError($param, 'Cannot use `resource` as a parameter type.');
// no break

@ -0,0 +1,21 @@
--TEST--
Static Class Property Read/Write Test
--FILE--
<?php
class Worker
{
public static ?stdClass $event = null;
public static string $eventLoopClass = 'Select';
public static function init() {
static::$eventLoopClass = static::$event ?: static::$eventLoopClass;
var_dump(static::$eventLoopClass);
}
}
function main() {
Worker::init();
}
?>
--EXPECT--
string(6) "Select"
Loading…
Cancel
Save