Skip to content

Commit 1d79eae

Browse files
Add non regression test (#5545)
1 parent 311b589 commit 1d79eae

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)