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 @@ +