File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -3795,6 +3795,10 @@ private function processSureTypesForConditionalExpressionsAfterAssign(Scope $sco
3795
3795
continue ;
3796
3796
}
3797
3797
3798
+ if ($ expr ->name === $ variableName ) {
3799
+ continue ;
3800
+ }
3801
+
3798
3802
if (!isset ($ conditionalExpressions [$ exprString ])) {
3799
3803
$ conditionalExpressions [$ exprString ] = [];
3800
3804
}
@@ -3825,6 +3829,10 @@ private function processSureNotTypesForConditionalExpressionsAfterAssign(Scope $
3825
3829
continue ;
3826
3830
}
3827
3831
3832
+ if ($ expr ->name === $ variableName ) {
3833
+ continue ;
3834
+ }
3835
+
3828
3836
if (!isset ($ conditionalExpressions [$ exprString ])) {
3829
3837
$ conditionalExpressions [$ exprString ] = [];
3830
3838
}
Original file line number Diff line number Diff line change @@ -1157,6 +1157,8 @@ public function dataFileAsserts(): iterable
1157
1157
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8568.php ' );
1158
1158
yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/DeadCode/data/bug-8620.php ' );
1159
1159
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8635.php ' );
1160
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8625.php ' );
1161
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8621.php ' );
1160
1162
}
1161
1163
1162
1164
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug8621 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ class HelloWorld
8
+ {
9
+ /**
10
+ * @param array<string> $data
11
+ */
12
+ public function rows (array $ data ): void
13
+ {
14
+ $ even = true ;
15
+
16
+ echo "<table> " ;
17
+ foreach ($ data as $ datum )
18
+ {
19
+ $ even = !$ even ;
20
+ assertType ('bool ' , $ even );
21
+
22
+ echo "<tr class=' " . ($ even ? 'even ' :'odd ' ) . "'> " ;
23
+ echo "<td> {$ datum }</td></tr> " ;
24
+ }
25
+ echo "</table> " ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug8625 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ class HelloWorld
8
+ {
9
+ public static function sayHello (): void
10
+ {
11
+ $ key = false ;
12
+ $ loopArray = [1 , 2 , 3 ];
13
+ foreach ($ loopArray as $ i ) {
14
+ $ key = $ key === false ;
15
+ assertType ('bool ' , $ key );
16
+ if ($ key ) {
17
+ echo "i= $ i key is true \n" ;
18
+ } else {
19
+ echo "i= $ i key is false \n" ;
20
+ }
21
+ }
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments