Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BitScout opened this issue Feb 22, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1033
Closed
Labels

Comments

@BitScout
Copy link

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

@BitScout BitScout changed the title PHPStand thinks array_column returns an array which has arrays as keys PHPStan thinks array_column returns an array which has arrays as keys Feb 22, 2022
@ondrejmirtes
Copy link
Member

/cc @jlherren (the author of phpstan/phpstan-src#970 and phpstan/phpstan-src#948) - can you please look into this to see who's wrong here? :) Thanks!

@jlherren
Copy link

Oof, yes arrays as keys is weird. Most likely there should be a ArrayType::castToArrayKeyType() on the key type. I'm looking into it.

@github-actions
Copy link

github-actions bot commented Apr 3, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants