Skip to content

Commit 76fd431

Browse files
committed
added test
1 parent 0d3dd3a commit 76fd431

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,10 @@ public function testBug14117(): void
13891389
'Variable $value might not be defined.',
13901390
49,
13911391
],
1392+
[
1393+
'Undefined variable: $value',
1394+
65
1395+
]
13921396
]);
13931397
}
13941398

tests/PHPStan/Rules/Variables/data/bug-14117.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ function baz(): void {
4646
}
4747

4848
if ($key === 3) {
49-
echo $value; // this one SHOULD report "might not be defined" because $key === 3 doesn't guarantee either earlier block ran
49+
echo $value; // SHOULD report "is not defined"
50+
}
51+
}
52+
53+
function boo(): void {
54+
$key = rand(0, 2);
55+
56+
if ($key === 1) {
57+
$value = 'test';
58+
}
59+
60+
if ($key === 1) {
61+
unset($value);
62+
}
63+
64+
if ($key === 1) {
65+
echo $value;
5066
}
5167
}

0 commit comments

Comments
 (0)