Skip to content

PHPStan thinks array_column returns an array which has arrays as keys #6682

@BitScout

Description

@BitScout

Bug report

Using phpstan 1.4.6 on PHP 7.4

Hi, 21 days ago, so right after the release of v1.4.4 (22 days ago) the daily build on ekino/phpstan-banned-code for PHP 7.4 broke. Could it be possible that this is due to this pull request? phpstan/phpstan-src#948

Code snippet that reproduces the problem

Example: https://phpstan.org/r/ac9d1992-138e-4925-82cd-1de3e3f93676

Expected output

phpstan analyze complains:

Line 16: Property Example::$myData (array) does not accept
array<array<string, string>|int|string|null, array<string, array<string, string>|string|null>>.

which in a simplified version means that phpstan thinks that array_column will return an
array<array|int|string|null, array>, in other words an array that can have arrays as its keys.

So thanks to your great bug report template which asks all the right questions I just realised why I got this message.

Now my followup question: Is this logic correct? It seems to me PHP really puts an integer as the key if you try with an array.
In this example here I intentionally put "foo" instead of "type" into array_column to provoke the problem:
http://sandbox.onlinephpfunctions.com/code/381d0182b85cc698b02b18b82cd9dae0da3f7a00

Did PHPStan help you today? Did it make you happy in any way?

PHPStan always makes me happy, it keeps my code clean and kills lots of bugs in their larva stage! <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions