Skip to content

Commit 4ddc2b1

Browse files
phpstan-botVincentLanglet
authored andcommitted
Add regression test for #11984
Closes phpstan/phpstan#11984
1 parent 4acc7e0 commit 4ddc2b1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,4 +1267,14 @@ public function testBug9023(): void
12671267
$this->analyse([__DIR__ . '/data/bug-9023.php'], []);
12681268
}
12691269

1270+
public function testBug11984(): void
1271+
{
1272+
$this->cliArgumentsVariablesRegistered = true;
1273+
$this->polluteScopeWithLoopInitialAssignments = false;
1274+
$this->checkMaybeUndefinedVariables = true;
1275+
$this->polluteScopeWithAlwaysIterableForeach = true;
1276+
1277+
$this->analyse([__DIR__ . '/data/bug-11984.php'], []);
1278+
}
1279+
12701280
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11984;
4+
5+
class Foo
6+
{
7+
/**
8+
* @return array<string, mixed>
9+
*/
10+
public function loadFromFile(): array
11+
{
12+
return ['x' => 1];
13+
}
14+
15+
/**
16+
* @return array<string, mixed>
17+
*/
18+
public function test(): array
19+
{
20+
while (true) {
21+
try {
22+
$data = $this->loadFromFile();
23+
24+
break;
25+
} catch (\Exception $ex) {
26+
}
27+
}
28+
29+
return $data;
30+
}
31+
}

0 commit comments

Comments
 (0)