diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index edf43899..036ce139 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1430,6 +1430,10 @@ class CompilerBase extends \PhpAot\Core\Translator $this->appendCapturedStmtLines($code, $afterStmts); $condExpr = $tmpVar; } + + if ($cond instanceof Expr\Assign) { + $condExpr = '(' . $condExpr . ')'; + } $code .= $openPrefix . '(' . $condExpr . ') {' . PHP_EOL; return $code; } @@ -4109,10 +4113,8 @@ class CompilerBase extends \PhpAot\Core\Translator 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