-
Notifications
You must be signed in to change notification settings - Fork 570
Expand file tree
/
Copy pathbug-12653.php
More file actions
42 lines (35 loc) · 869 Bytes
/
bug-12653.php
File metadata and controls
42 lines (35 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php declare(strict_types = 1);
namespace Bug12653;
use function PHPStan\Testing\assertType;
class Reproduction
{
const TYPE_XXX = 'xxx';
const TYPE_YYY = 'yyy';
const TYPE_ZZZ = 'zzz';
/**
* @return array<'a'|'b'|'c'|'d',Reproduction::TYPE_*>
*/
public function main()
{
$list = [
'a' => Reproduction::TYPE_XXX,
'b' => Reproduction::TYPE_YYY,
'c' => Reproduction::TYPE_ZZZ,
'd' => Reproduction::TYPE_XXX,
];
$keys = ['a', 'b', 'c', 'd'];
$found = false;
foreach ($keys as $key) {
if ($list[$key] === Reproduction::TYPE_XXX) {
// The first matched key is kept and subsequent matched keys are rewritten.
if (!$found) {
$found = true;
} else {
$list[$key] = Reproduction::TYPE_ZZZ;
}
}
}
assertType("array{a: 'xxx'|'zzz', b: 'yyy'|'zzz', c: 'zzz', d: 'xxx'|'zzz'}", $list);
return $list;
}
}