use positive-int in array_count_values()#645
Conversation
|
Error is unrelated |
resources/functionMap.php
Outdated
| 'array_column' => ['array', 'array'=>'array', 'column_key'=>'mixed', 'index_key='=>'mixed'], | ||
| 'array_combine' => ['array|false', 'keys'=>'array', 'values'=>'array'], | ||
| 'array_count_values' => ['int[]', 'input'=>'array'], | ||
| 'array_count_values' => ['array<int|string, 0|positive-int>', 'input'=>'array'], |
There was a problem hiding this comment.
just do array<0|positive-int> - the difference is that the key will be BenevolentUnionType
There was a problem hiding this comment.
Of course a dynamic return type extension would be nice and precise :)
There was a problem hiding this comment.
Of course a dynamic return type extension would be nice and precise :)
Agree. Was just hunting low hanging fruits in the signature file
There was a problem hiding this comment.
BenevolentUnionType
i read this classname in a lot of spots, but have no idea what it is/why its better/different then e.g. array-key or int|string
There was a problem hiding this comment.
The difference is that if you have array<string> then:
foreach ($array as $k => $v) {
// $k is BenevolentUnionType of int|string
$this->requireString($k); // PHPStan does not complain
$this->requireInt($k); // PHPStan does not complain
$this->requireStdClass($k); // PHPStan complains on level 5+
}But with array<int|string, string>:
foreach ($array as $k => $v) {
// $k is UnionType of int|string
$this->requireString($k); // PHPStan complains on level 7+
$this->requireInt($k); // PHPStan complains on level 7+
$this->requireStdClass($k); // PHPStan complains on level 5+
$this->requireIntOrString($k); // PHPStan does not complain
}|
Thank you! |
No description provided.