forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-13857.php
More file actions
24 lines (20 loc) · 765 Bytes
/
bug-13857.php
File metadata and controls
24 lines (20 loc) · 765 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
<?php declare(strict_types = 1);
namespace Bug13857;
use function PHPStan\Testing\assertType;
/**
* @param array<int, array{state: string}> $array
*/
function test(array $array, int $id): void {
$array[$id]['state'] = 'foo';
// only one element was set to 'foo', not all of them.
// correct type would be: non-empty-array<int, array{state: string}>
assertType('non-empty-array<int, array{state: string}>', $array);
}
/**
* @param array<string, array{name: string, age: int}> $people
*/
function test2(array $people, string $key): void {
$people[$key]['name'] = 'John';
// age becomes optional because $key might not exist yet, creating array{name: 'John'} without age
assertType('non-empty-array<string, array{name: string, age?: int}>', $people);
}