Skip to content

Commit 9b3d9ad

Browse files
phpstan-botclaude
andcommitted
Add non-regression test for phpstan/phpstan#1311
Verifies that by-reference foreach without key variable correctly tracks type overwrites when casting values (e.g. `$item = (string) $item`). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f72b536 commit 9b3d9ad

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Bug1311;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
/**
10+
* @var array<int, string>
11+
*/
12+
private $list = [];
13+
14+
/**
15+
* @param array<int, int> $temp
16+
*/
17+
public function convertList(array $temp): void
18+
{
19+
foreach ($temp as &$item) {
20+
$item = (string) $item;
21+
}
22+
23+
assertType('array<int, lowercase-string&numeric-string&uppercase-string>', $temp);
24+
25+
$this->list = $temp;
26+
}
27+
}

0 commit comments

Comments
 (0)