diff --git a/src/Parser/AssignOpTrait.php b/src/Parser/AssignOpTrait.php index 745f9be2..f15aec98 100644 --- a/src/Parser/AssignOpTrait.php +++ b/src/Parser/AssignOpTrait.php @@ -583,9 +583,7 @@ trait AssignOpTrait } if ($this->isAssignOpConcat($op)) { - $items = []; - $this->flattenConcatExpr($node->expr, $items); - if (count($items) === 1) { + if (!($node->expr instanceof Expr\BinaryOp\Concat)) { return $var . '.append(' . $this->parseExprAsValue($node->expr) . ')'; } return $var . ' = php::toString(' . $this->parseFlattenedConcat($node->expr, [$var]) . ')'; diff --git a/src/Parser/SelectionExpressionTrait.php b/src/Parser/SelectionExpressionTrait.php index 4f7cd90a..9cd801e4 100644 --- a/src/Parser/SelectionExpressionTrait.php +++ b/src/Parser/SelectionExpressionTrait.php @@ -25,7 +25,7 @@ trait SelectionExpressionTrait [$cond, $condBeforeStmts, $condAfterStmts] = $this->parseExprWithCapturedStmts($expr->cond); $ifBeforeStmtCount = count($this->context->beforeStmtLines); $ifAfterStmtCount = count($this->context->afterStmtLines); - $if = $this->parseExpr($expr->if); + $if = $this->parseExprAsValue($expr->if); $ifBeforeStmts = array_slice($this->context->beforeStmtLines, $ifBeforeStmtCount); $ifAfterStmts = array_slice($this->context->afterStmtLines, $ifAfterStmtCount); $this->context->beforeStmtLines = array_slice($this->context->beforeStmtLines, 0, $ifBeforeStmtCount); @@ -33,7 +33,7 @@ trait SelectionExpressionTrait $elseBeforeStmtCount = count($this->context->beforeStmtLines); $elseAfterStmtCount = count($this->context->afterStmtLines); - $else = $this->parseExpr($expr->else); + $else = $this->parseExprAsValue($expr->else); $elseBeforeStmts = array_slice($this->context->beforeStmtLines, $elseBeforeStmtCount); $elseAfterStmts = array_slice($this->context->afterStmtLines, $elseAfterStmtCount); $this->context->beforeStmtLines = array_slice($this->context->beforeStmtLines, 0, $elseBeforeStmtCount); @@ -206,4 +206,3 @@ trait SelectionExpressionTrait } } - diff --git a/tests/compiler/operator/concat-assign-inherited-property.phpt b/tests/compiler/operator/concat-assign-inherited-property.phpt new file mode 100644 index 00000000..e93340d1 --- /dev/null +++ b/tests/compiler/operator/concat-assign-inherited-property.phpt @@ -0,0 +1,29 @@ +--TEST-- +concat assignment to an inherited property preserves value and reference arguments +--FILE-- +query .= '.sort(' . json_encode(['id' => 1]) . ')'; + $this->query .= '.skip(' . 2 . ')'; + $this->query .= ';'; + return $this->query; + } +} + +function main(): void +{ + $connection = new MongoConnection(); + var_dump($connection->build()); +} +?> +--EXPECT-- +string(24) ".sort({"id":1}).skip(2);" diff --git a/tests/compiler/operator/ternary-void-branches.phpt b/tests/compiler/operator/ternary-void-branches.phpt new file mode 100644 index 00000000..c69c61eb --- /dev/null +++ b/tests/compiler/operator/ternary-void-branches.phpt @@ -0,0 +1,48 @@ +--TEST-- +ternary expressions convert void branches to null after their side effects +--FILE-- +updateLockVersion() + : $this->recordLockVersion(); + } + + public function calls(): int + { + return $this->calls; + } + + private function updateLockVersion(): void + { + echo "update\n"; + $this->calls++; + } + + private function recordLockVersion(): void + { + echo "record\n"; + $this->calls++; + } +} + +function main(): void +{ + $lock = new OptimisticLock(); + var_dump($lock->check(true)); + var_dump($lock->check(false)); + var_dump($lock->calls()); +} +?> +--EXPECT-- +update +NULL +record +NULL +int(2)