Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ lint:
--exclude tests/PHPStan/Rules/Properties/data/property-override-attr-missing.php \
--exclude tests/PHPStan/Rules/Properties/data/override-attr-on-property.php \
--exclude tests/PHPStan/Rules/Properties/data/property-override-attr.php \
--exclude tests/PHPStan/Rules/Operators/data/bug-3585.php \
src tests

install-paratest:
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Operators/InvalidAssignVarRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function processNode(Node $node, Scope $scope): array
private function containsNonAssignableExpression(Expr $expr): bool
{
if ($expr instanceof Expr\Variable) {
return false;
return $expr->name === 'this';
}

if ($expr instanceof Expr\PropertyFetch) {
Expand Down
30 changes: 30 additions & 0 deletions tests/PHPStan/Rules/Operators/InvalidAssignVarRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,34 @@ public function testRule(): void
]);
}

public function testBug3585(): void
{
$this->analyse([__DIR__ . '/data/bug-3585.php'], [
[
'Expression on left side of assignment is not assignable.',
9,
],
[
'Expression on left side of assignment is not assignable.',
10,
],
[
'Expression on left side of assignment is not assignable.',
11,
],
[
'Expression on left side of assignment is not assignable.',
12,
],
[
'Expression on left side of assignment is not assignable.',
17,
],
[
'Expression on left side of assignment is not assignable.',
23,
],
]);
}

}
24 changes: 24 additions & 0 deletions tests/PHPStan/Rules/Operators/data/bug-3585.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types = 1);

namespace Bug3585;

class Foo
{
public function doFoo(): void
{
$this = 1;
$this = new self();
$this .= 'foo';
[$this] = [1];
}

public static function doBar(): void
{
$this = 1; // allowed in static context? Actually no, PHP still forbids it
}
}

function baz(): void
{
$this = 1; // PHP forbids this too
}
Loading