diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index c216b715..34957002 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1375,8 +1375,8 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont return $this->parseConstFetch($expr); case 'Expr_Assign': case 'Expr_AssignRef': - if (!$this->isVarExpr($expr->var)) { - $this->fatalError($expr, 'When an assignment expression serves as an rvalue, it must be an assignment of a variable'); + if (!$this->isVarExpr($expr->var) && !$this->isPropertyFetch($expr->var) && !$this->isArrayDimFetch($expr->var)) { + $this->fatalError($expr, 'When an assignment expression serves as an rvalue, it must be an assignment of a variable, property, or array element'); } return $this->parseExpr($expr); default: diff --git a/src/Php/Parser/AssignOpTrait.php b/src/Php/Parser/AssignOpTrait.php index 021d655e..24661283 100644 --- a/src/Php/Parser/AssignOpTrait.php +++ b/src/Php/Parser/AssignOpTrait.php @@ -85,13 +85,13 @@ trait AssignOpTrait $chain = array_reverse($chain); $list = []; - $list[] = $this->getIndent() . $tmpVar . ' = ' . $this->parseExpr($next); + $list[] = $tmpVar . ' = ' . $this->parseExpr($next); $rightVar = new Variable($tmpVar); foreach ($chain as $var) { - $list[] = $this->getIndent() . $this->parseAssignFinally($var, $rightVar); + $list[] = $this->parseAssignFinally($var, $rightVar); } - return implode(";\n" . $this->getIndent(), $list); + return '(' . implode(', ', $list) . ')'; } protected function parseAssign(Expr\Assign $v): string diff --git a/tests/aot/basic/multi-var-assign.phpt b/tests/aot/basic/multi-var-assign.phpt new file mode 100644 index 00000000..d2a10236 --- /dev/null +++ b/tests/aot/basic/multi-var-assign.phpt @@ -0,0 +1,50 @@ +--TEST-- +Multi-variable assignment: property assignment as rvalue in constructor argument expression +--FILE-- +value = new Test2($this->arr[0] = $this->value2 = 123); + var_dump($this->value2, $this->arr); + $this->value = new Test2($this->arr[0] = $this->value3 = $this->value2 = 456); + var_dump($this->value2, $this->value3, $this->arr); + } +} + +function main() +{ + new Test; +} +?> +--EXPECT-- +int(123) +int(123) +array(1) { + [0]=> + int(123) +} +int(456) +int(456) +int(456) +array(1) { + [0]=> + int(456) +}