Skip to content

Commit

Permalink
add failing test from phpstan/phpstan#8467
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed Dec 7, 2022
1 parent 2ca6118 commit aa2c4e9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,4 +927,22 @@ public function testBug5805(): void
$this->analyse([__DIR__ . '/data/bug-5805.php'], []);
}

public function testBug8467c(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = false;
$this->analyse([__DIR__ . '/data/bug-8467c.php'], [
[
'Variable $v might not be defined.',
16,
],
[
'Variable $v might not be defined.',
18,
],
]);
}

}
23 changes: 23 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-8467c.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types = 1);

namespace Bug8467c;

/**
* @param int[] $a
* @return void
*/
function foo(array $a, int $key): void
{
$k = [];
foreach ($a as $v) {
$k[$key][] = $v;
}

echo $v;
foreach ($k as $values) {
echo $v;
foreach ($values as $v) {
echo $v;
}
}
}

0 comments on commit aa2c4e9

Please sign in to comment.