refactor(php): 移除属性赋值解析方法并优化对象初始化

- 删除了 Expr_PropertyFetch 类型的属性赋值解析逻辑
- 在 Test 类中添加构造函数以简化对象初始化
- 更新示例代码使用构造函数进行对象创建和属性赋值
pull/1/head
韩天峰 8 months ago
parent f8be1767e6
commit 9b94b287cb
  1. 10
      examples/obj.php
  2. 2
      src/Php/CompilerBase.php

@ -5,6 +5,12 @@ class Test
public int $a; public int $a;
public int $b; public int $b;
public function __construct(int $a, int $b)
{
$this->a = $a;
$this->b = $b;
}
public function test() public function test()
{ {
return $this->a + $this->b; return $this->a + $this->b;
@ -13,9 +19,7 @@ class Test
function main() function main()
{ {
$obj = new Test(); $obj = new Test(1, 2);
$obj->a = 1;
$obj->b = 2;
$arr = array(); $arr = array();
$arr['obj'] = $obj; $arr['obj'] = $obj;

@ -772,8 +772,6 @@ class CompilerBase extends \PhpAot\Core\Translator
if ($left->getType() === self::EXPR_ARRAY_DIM_FETCH) { if ($left->getType() === self::EXPR_ARRAY_DIM_FETCH) {
return $this->parseAssignArrayDim($left, $right); return $this->parseAssignArrayDim($left, $right);
} elseif ($left->getType() === 'Expr_PropertyFetch') {
return $this->parseAssignPropertyFetch($left, $right);
} elseif ($left->getType() === 'Expr_StaticPropertyFetch') { } elseif ($left->getType() === 'Expr_StaticPropertyFetch') {
$class = $this->identifierToStr($left->class); $class = $this->identifierToStr($left->class);
$propName = $this->identifierToStr($left->name); $propName = $this->identifierToStr($left->name);

Loading…
Cancel
Save