From 73f84217dbe3c1481e333e7e0ba01c4767f65570 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 7 Jan 2026 14:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=9D=99=E6=80=81=E7=B1=BB?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E8=AF=BB=E5=86=99=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/Translator.php | 14 ++++- tests/aot/assign-compare.phpt | 11 ++++ .../aot/static_class_property_read_write.phpt | 61 +++++++++++++++++++ tests/aot/static_property_test.inc | 47 ++++++++++++++ 4 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 tests/aot/assign-compare.phpt create mode 100644 tests/aot/static_class_property_read_write.phpt create mode 100644 tests/aot/static_property_test.inc diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 5f14c671..2f4ac5d1 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -463,6 +463,7 @@ class Translator extends \PhpAot\Core\Translator case self::EXPR_VARIABLE: return $this->escapeVarName($expr->name); case 'Name': + case 'VarLikeIdentifier': case 'Identifier': return $expr->name; case 'Scalar_Int': @@ -667,7 +668,6 @@ class Translator extends \PhpAot\Core\Translator return $this->parseBinaryOpLogicalOr($expr); case 'Expr_BinaryOp_LogicalXor': return $this->parseBinaryOpLogicalXor($expr); - // 减法 case 'Expr_BinaryOp_Minus': return $this->parseBinaryOpMinus($expr); case 'Expr_Array': @@ -700,6 +700,8 @@ class Translator extends \PhpAot\Core\Translator return $this->parseMethodCall($expr); case 'Expr_StaticCall': return $this->parseStaticCall($expr); + case 'Expr_StaticPropertyFetch': + return $this->parseStaticPropertyFetch($expr); case 'Expr_Include': return $this->parseInclude($expr); case 'Expr_Eval': @@ -780,6 +782,11 @@ class Translator extends \PhpAot\Core\Translator $array = $this->parseIdentifier($left->var); $propName = $this->identifierToStr($left->name); return "$array.setProperty($propName, " . $this->trimBrackets($this->parseExpr($right)) . ")"; + } elseif ($left->getType() === 'Expr_StaticPropertyFetch') { + $class = $this->identifierToStr($left->class); + $propName = $this->identifierToStr($left->name); + $value = $this->trimBrackets($this->parseExpr($right)); + return "php::setStaticProperty($class, $propName, $value)"; } elseif ($right->getType() === 'Expr_Assign') { $chain[] = $left; while ($right->getType() === 'Expr_Assign') { @@ -2434,6 +2441,11 @@ class Translator extends \PhpAot\Core\Translator } } + private function parseStaticPropertyFetch(Node $expr): string + { + return 'php::getStaticProperty(' . $this->identifierToStr($expr->class) . ', ' . $this->identifierToStr($expr->name) . ')'; + } + private function parseMagicConstLine(Node $expr): int { return $expr->getStartLine(); diff --git a/tests/aot/assign-compare.phpt b/tests/aot/assign-compare.phpt new file mode 100644 index 00000000..78fb90f5 --- /dev/null +++ b/tests/aot/assign-compare.phpt @@ -0,0 +1,11 @@ +--TEST-- +assign compare +--FILE-- + +--EXPECT-- +bool(true) \ No newline at end of file diff --git a/tests/aot/static_class_property_read_write.phpt b/tests/aot/static_class_property_read_write.phpt new file mode 100644 index 00000000..0666fec7 --- /dev/null +++ b/tests/aot/static_class_property_read_write.phpt @@ -0,0 +1,61 @@ +--TEST-- +Static Class Property Read/Write Test +--FILE-- + +--EXPECTF-- +Initial public property: initial_value +Initial protected property: protected_value +Initial private property: private_value +Initial default property: default_value +Modified public property: modified_public +Modified protected property: modified_protected +Modified private property: modified_private +Modified default property: modified_default +Initial counter: 0 +After increment 1: 1 +After increment 2: 2 +Final counter: 2 +Int property: 42 +Float property: %s +Bool property: true +Modified int property: 100 +Modified float property: 2.71 +Modified bool property: false \ No newline at end of file diff --git a/tests/aot/static_property_test.inc b/tests/aot/static_property_test.inc new file mode 100644 index 00000000..3b4a69fe --- /dev/null +++ b/tests/aot/static_property_test.inc @@ -0,0 +1,47 @@ +