diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index ca9b1830..8fe5987d 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1437,6 +1437,10 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont $this->appendCapturedStmtLines($code, $afterStmts); $condExpr = $tmpVar; } + + if ($cond instanceof Expr\Assign) { + $condExpr = '(' . $condExpr . ')'; + } $code .= $openPrefix . '(' . $condExpr . ') {' . PHP_EOL; return $code; } @@ -4115,10 +4119,8 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont if ($tail !== '') { $code .= $this->getIndent() . '} else {' . PHP_EOL; $code .= $tail; - $code .= $this->getIndent() . '}'; - } else { - $code .= $this->getIndent() . '}'; } + $code .= $this->getIndent() . '}'; return $code; }; diff --git a/tests/aot/basic/condition-assign.phpt b/tests/aot/basic/condition-assign.phpt new file mode 100644 index 00000000..645f7868 --- /dev/null +++ b/tests/aot/basic/condition-assign.phpt @@ -0,0 +1,12 @@ +--TEST-- +condition assign +--FILE-- + +--EXPECT-- +success