From b1662f3cc9b09d57f0e17a741830284db748cf97 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 27 Feb 2026 20:14:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=AE=BF=E9=97=AE=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 EXPR_PROPERTY_FETCH 常量用于标识属性访问表达式 - 在解析器中实现对 Expr_PropertyFetch 节点的支持 - 使用 parseIdentifier 方法替代 convertToObject 方法处理对象属性访问 - 添加对象链式访问操作符测试用例 - 支持属性连接赋值操作符 (.=) 的解析和执行 --- src/Php/CompilerBase.php | 9 +++++++-- tests/aot/object-link-002.phpt | 14 ++++++++++++++ tests/aot/object-link-003.phpt | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/aot/object-link-002.phpt create mode 100644 tests/aot/object-link-003.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 538417dc..6b7b792d 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -67,6 +67,7 @@ class CompilerBase extends \PhpAot\Core\Translator public const string EXPR_NEW = 'Expr_New'; public const string EXPR_ARRAY_DIM_FETCH = 'Expr_ArrayDimFetch'; + public const string EXPR_PROPERTY_FETCH = 'Expr_PropertyFetch'; public const string NAMESPACE_SEPARATOR = '__'; @@ -361,7 +362,7 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->parseArray($expr); case self::EXPR_ARRAY_DIM_FETCH: return $this->parseArrayDimFetch($expr, $this->inAssignExpr); - case 'Expr_PropertyFetch': + case self::EXPR_PROPERTY_FETCH: return $this->parsePropertyFetch($expr, $this->inAssignExpr); case 'Expr_BinaryOp_ShiftLeft': return $this->parseBinaryOpShiftLeft($expr); @@ -1828,6 +1829,10 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->parseArrayDimStore($node->var->var, $dim, $tmpVar); } + + if ($this->isAssignOpConcat($op)) { + return $var . '.append(' . $expr . ')'; + } return $var . ' ' . $op . ' (' . $expr . ')'; } @@ -2860,7 +2865,7 @@ class CompilerBase extends \PhpAot\Core\Translator $object = $expr->var; $property = $expr->name; $id = $this->getPropertyIdentifier($object, $property); - return $this->convertToObject($object) . '.attr(' . $id . ', ' . $this->escapeBool($update) . ')'; + return $this->parseIdentifier($object) . '.attr(' . $id . ', ' . $this->escapeBool($update) . ')'; } protected function parseAssignOpShiftRight(Node $node): string diff --git a/tests/aot/object-link-002.phpt b/tests/aot/object-link-002.phpt new file mode 100644 index 00000000..c3ed55e8 --- /dev/null +++ b/tests/aot/object-link-002.phpt @@ -0,0 +1,14 @@ +--TEST-- +object link operator 002 +--FILE-- +prop = new stdClass(); + $o->prop->value = "value"; + var_dump($o->prop->value); +} +?> +--EXPECT-- +string(5) "value" diff --git a/tests/aot/object-link-003.phpt b/tests/aot/object-link-003.phpt new file mode 100644 index 00000000..23069b6d --- /dev/null +++ b/tests/aot/object-link-003.phpt @@ -0,0 +1,15 @@ +--TEST-- +object link operator 003 +--FILE-- +prop = new stdClass(); + $o->prop->value = "value"; + $o->prop->value .= " 2025"; + var_dump($o->prop->value); +} +?> +--EXPECT-- +string(10) "value 2025"