Skip to content

Commit 27f95cc

Browse files
committed
test readonly class
1 parent 4292e7c commit 27f95cc

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tests/PHPStan/Analyser/nsrt/remember-readonly-constructor-narrowed.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<?php // lint >= 8.1
1+
<?php // lint >= 8.2
22

33
namespace RememberReadOnlyConstructor;
44

55
use function PHPStan\Testing\assertType;
66

7-
class HelloWorldReadonly {
7+
class HelloWorldReadonlyProperty {
88
private readonly int $i;
99

1010
public function __construct()
@@ -21,6 +21,23 @@ public function doFoo() {
2121
}
2222
}
2323

24+
readonly class HelloWorldReadonlyClass {
25+
private int $i;
26+
27+
public function __construct()
28+
{
29+
if (rand(0,1)) {
30+
$this->i = 4;
31+
} else {
32+
$this->i = 10;
33+
}
34+
}
35+
36+
public function doFoo() {
37+
assertType('4|10', $this->i);
38+
}
39+
}
40+
2441

2542
class HelloWorldRegular {
2643
private int $i;

0 commit comments

Comments
 (0)