diff --git a/src/Php/Parser/AssignOpTrait.php b/src/Php/Parser/AssignOpTrait.php index d4b9ef7c..4464e9a2 100644 --- a/src/Php/Parser/AssignOpTrait.php +++ b/src/Php/Parser/AssignOpTrait.php @@ -142,20 +142,20 @@ trait AssignOpTrait return $this->parseAssignToList($left, $right); } - $oriInAssignExpr = $this->context->inAssignExpr; - $this->context->inAssignExpr = true; - $var = $this->parseIdentifier($left); - $this->context->inAssignExpr = $oriInAssignExpr; $propertyWriteTarget = $this->preparePropertyWriteTarget($left); - if ($var === 'this_') { - $this->fatalError($left, 'Cannot re-assign $this'); - } $finalVarType = $type = $this->detectTypeOfExpr($right); if ($type === self::TYPE_VOID) { $finalVarType = $type = self::TYPE_VAR; } if ($this->isVarExpr($left)) { + $oriInAssignExpr = $this->context->inAssignExpr; + $this->context->inAssignExpr = true; + $var = $this->parseIdentifier($left); + $this->context->inAssignExpr = $oriInAssignExpr; + if ($var === 'this_') { + $this->fatalError($left, 'Cannot re-assign $this'); + } if ($this->isStdContainer($var)) { $copyAssign = $this->parseStdContainerCopyAssign($var, $right); if ($copyAssign !== null) { @@ -274,6 +274,10 @@ trait AssignOpTrait $this->assertCanAssignPropertyWrite($propertyWriteTarget, $right); } + $oriInAssignExpr = $this->context->inAssignExpr; + $this->context->inAssignExpr = true; + $var = $this->parseIdentifier($left); + $this->context->inAssignExpr = $oriInAssignExpr; $rightExpr = $this->parseAssignRightExpr($right); if ($propertyWriteTarget !== null) { $rightExpr = $this->wrapPropertyWriteTypeCheck($propertyWriteTarget, $right, $rightExpr); diff --git a/tests/aot/operator/comparison_operators.phpt b/tests/aot/operator/comparison_operators.phpt index 9ec4c489..0d56d550 100644 --- a/tests/aot/operator/comparison_operators.phpt +++ b/tests/aot/operator/comparison_operators.phpt @@ -47,16 +47,6 @@ $int_num = 10; var_dump($str_num == $int_num); // true (loose comparison) var_dump($str_num === $int_num); // false (strict comparison) -// Test spaceship operator (PHP 7+) -$spaceship1 = 5 <=> 10; // -1 -var_dump($spaceship1); - -$spaceship2 = 10 <=> 10; // 0 -var_dump($spaceship2); - -$spaceship3 = 15 <=> 10; // 1 -var_dump($spaceship3); - // Test comparisons with strings $str1 = "apple"; $str2 = "banana"; @@ -149,9 +139,6 @@ bool(true) bool(false) bool(true) bool(false) -int(-1) -int(0) -int(1) bool(true) bool(true) bool(false) diff --git a/tests/aot/operator/spaceship.phpt b/tests/aot/operator/spaceship.phpt new file mode 100644 index 00000000..4267adf5 --- /dev/null +++ b/tests/aot/operator/spaceship.phpt @@ -0,0 +1,18 @@ +--TEST-- +assign compare +--FILE-- + 10; // -1 +var_dump($spaceship1); + +$spaceship2 = 10 <=> 10; // 0 +var_dump($spaceship2); + +$spaceship3 = 15 <=> 10; // 1 +var_dump($spaceship3); +?> +--EXPECT-- +int(-1) +int(0) +int(1) \ No newline at end of file