Skip to content

Commit

Permalink
Allow non-string keys
Browse files Browse the repository at this point in the history
Although it would be stupid to provide an array with exclusively
non-string keys, it's possible to have array with a bit of both.

See for instance
https://github.com/doctrine/dbal/blob/155d028be084ef69110d09938c57c351a2126e5d/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php#L263-L276
  • Loading branch information
greg0ire committed Apr 27, 2020
1 parent e1c6fcc commit 082c1fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Psalm/Internal/Stubs/CoreGenericFunctions.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,12 @@ function uksort(array &$arr, callable $callback): bool
}

/**
* @psalm-template K of array-key
* @psalm-template T
*
* @param array<string, T> $arr
* @param array<K,T> $arr
*
* @return array<string, T>
* @return array<K,T>
* @psalm-pure
*/
function array_change_key_case(array $arr, int $case = CASE_LOWER)
Expand Down
6 changes: 6 additions & 0 deletions tests/ArrayFunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,12 @@ function init(string $code) : string {
return "";
}'
],
'arrayChangeKeyCaseWithNonStringKeys' => [
'<?php
$a = [42, "A" => 42];
echo array_change_key_case($a, CASE_LOWER)[0];'
],
];
}

Expand Down

0 comments on commit 082c1fa

Please sign in to comment.