Skip to content

Commit c6a1c9b

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents a3f4219 + a275ce9 commit c6a1c9b

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ lint:
126126
--exclude tests/PHPStan/Rules/Properties/data/property-override-attr-missing.php \
127127
--exclude tests/PHPStan/Rules/Properties/data/override-attr-on-property.php \
128128
--exclude tests/PHPStan/Rules/Properties/data/property-override-attr.php \
129+
--exclude tests/PHPStan/Rules/Operators/data/bug-3585.php \
129130
src tests
130131

131132
install-paratest:

src/Rules/Operators/InvalidAssignVarRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function processNode(Node $node, Scope $scope): array
7272
private function containsNonAssignableExpression(Expr $expr): bool
7373
{
7474
if ($expr instanceof Expr\Variable) {
75-
return false;
75+
return $expr->name === 'this';
7676
}
7777

7878
if ($expr instanceof Expr\PropertyFetch) {

tests/PHPStan/Rules/Operators/InvalidAssignVarRuleTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,34 @@ public function testRule(): void
5959
]);
6060
}
6161

62+
public function testBug3585(): void
63+
{
64+
$this->analyse([__DIR__ . '/data/bug-3585.php'], [
65+
[
66+
'Expression on left side of assignment is not assignable.',
67+
9,
68+
],
69+
[
70+
'Expression on left side of assignment is not assignable.',
71+
10,
72+
],
73+
[
74+
'Expression on left side of assignment is not assignable.',
75+
11,
76+
],
77+
[
78+
'Expression on left side of assignment is not assignable.',
79+
12,
80+
],
81+
[
82+
'Expression on left side of assignment is not assignable.',
83+
17,
84+
],
85+
[
86+
'Expression on left side of assignment is not assignable.',
87+
23,
88+
],
89+
]);
90+
}
91+
6292
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug3585;
4+
5+
class Foo
6+
{
7+
public function doFoo(): void
8+
{
9+
$this = 1;
10+
$this = new self();
11+
$this .= 'foo';
12+
[$this] = [1];
13+
}
14+
15+
public static function doBar(): void
16+
{
17+
$this = 1; // allowed in static context? Actually no, PHP still forbids it
18+
}
19+
}
20+
21+
function baz(): void
22+
{
23+
$this = 1; // PHP forbids this too
24+
}

0 commit comments

Comments
 (0)