Skip to content

Commit b19af48

Browse files
committed
Regression test
Closes phpstan/phpstan#11241
1 parent daa8cc6 commit b19af48

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/PHPStan/Rules/Properties/WritingToReadOnlyPropertiesRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,19 @@ public function testPrivatePropertyTagRead(): void
122122
]);
123123
}
124124

125+
public function testBug11241(): void
126+
{
127+
$this->checkThisOnly = false;
128+
$this->analyse([__DIR__ . '/data/bug-11241.php'], [
129+
[
130+
'Property Bug11241\MagicProp::$id is not writable.',
131+
27,
132+
],
133+
[
134+
'Property Bug11241\ActualProp::$id is not writable.',
135+
30,
136+
],
137+
]);
138+
}
139+
125140
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Bug11241;
4+
5+
/** @property-read int $id */
6+
class MagicProp
7+
{
8+
/** @return mixed */
9+
public function __get(string $name) { echo $this->id; }
10+
/** @param mixed $v */
11+
public function __set(string $name, $v): void {}
12+
}
13+
14+
/** @property-read int $id */
15+
class ActualProp
16+
{
17+
private int $id = 0;
18+
19+
/** @return mixed */
20+
public function __get(string $name) { echo $this->id; }
21+
/** @param mixed $v */
22+
public function __set(string $name, $v): void {}
23+
}
24+
25+
function (): void {
26+
$x = new MagicProp;
27+
$x->id = 1;
28+
29+
$x = new ActualProp;
30+
$x->id = 1;
31+
};

0 commit comments

Comments
 (0)