File tree Expand file tree Collapse file tree
tests/PHPStan/Rules/Variables Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1517,6 +1517,15 @@ public function testBug11218(): void
15171517 $ this ->analyse ([__DIR__ . '/data/bug-11218.php ' ], []);
15181518 }
15191519
1520+ public function testBug4352 (): void
1521+ {
1522+ $ this ->cliArgumentsVariablesRegistered = true ;
1523+ $ this ->polluteScopeWithLoopInitialAssignments = false ;
1524+ $ this ->checkMaybeUndefinedVariables = true ;
1525+ $ this ->polluteScopeWithAlwaysIterableForeach = true ;
1526+ $ this ->analyse ([__DIR__ . '/data/bug-4352.php ' ], []);
1527+ }
1528+
15201529 public function testBug6688 (): void
15211530 {
15221531 $ this ->cliArgumentsVariablesRegistered = true ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug4352 ;
4+
5+ $ foo = [rand ()];
6+ $ found = false ;
7+
8+ foreach ($ foo as $ b ) {
9+ if ($ b > 2 ) {
10+ $ a = $ b ;
11+ $ found = true ;
12+ }
13+ }
14+
15+ if ($ found ) {
16+ /** @var int $a */
17+ echo $ a ;
18+ }
19+
20+ class A {
21+ public function foo (): void {
22+ $ foo = [rand ()];
23+ $ found = false ;
24+
25+ foreach ($ foo as $ b ) {
26+ if ($ b > 2 ) {
27+ $ a = $ b ;
28+ $ found = true ;
29+ }
30+ }
31+
32+ if ($ found ) {
33+ /** @var int $a */
34+ echo $ a ;
35+ }
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments