Re: Proposal: Adding an ARRAY_FILTER_REINDEX flag to array_values
| From: | Marco Pivetta | Date: | Mon, 20 Sep 2021 10:07:57 +0000 |
| Subject: | Re: Proposal: Adding an ARRAY_FILTER_REINDEX flag to array_values | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116106@lists.php.net to get a copy of this message | ||
On Mon, Sep 20, 2021 at 12:02 PM Eugene Sidelnyk <zsidelnik@gmail.com>
wrote:
> From my experience it is not that easy to locate bug like this.
>
Heyo, just a tip for you (and others in this thread), but if you use
vimeo/psalm and declare a list<T> for a type, then
array_filter()
that are missing an array_values() around it will be caught :)
```php
/** @return list<mixed> */
function foo(array $input): array {
return array_filter($input);
}
```
Will produce:
```
INFO: MixedReturnTypeCoercion - 5:12 - The type 'array<array-key,
non-empty-mixed>' is more general than the declared return type
'list<mixed>' for foo
```
See https://psalm.dev/r/f9c51f72c2
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/