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

array_map with two or more arrays: wrong keys inferred #5039

Closed
AlexeyOnsite opened this issue May 19, 2021 · 4 comments
Closed

array_map with two or more arrays: wrong keys inferred #5039

AlexeyOnsite opened this issue May 19, 2021 · 4 comments
Labels
Milestone

Comments

@AlexeyOnsite
Copy link

AlexeyOnsite commented May 19, 2021

Bug report

If using array_map with two or more arrays, resulting array keys are inferred wrong.

Code snippet that reproduces the problem

https://phpstan.org/r/6e13bd6d-b90f-4577-9c3d-da16da9eaa77

Expected output

As stated in the doc, numeric keys should be expected:

The returned array will preserve the keys of the array argument if and only if exactly one array is passed. If more than one array is passed, the returned array will have sequential integer keys.

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

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone May 19, 2021
@ondrejmirtes
Copy link
Member

@phpstan-bot
Copy link
Contributor

@AlexeyOnsite After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+5: Parameter #1 $callback of function array_map expects callable(0|1): mixed, Closure(mixed, mixed): 0|1 given.
 7: Offset 0 does not exist on array('a' => 0|1, 'b' => 0|1).
 8: Offset 1 does not exist on array('a' => 0|1, 'b' => 0|1, 0 => 0).
Full report
Line Error
5 `Parameter #1 $callback of function array_map expects callable(0
7 `Offset 0 does not exist on array('a' => 0
8 `Offset 1 does not exist on array('a' => 0

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@3e0ecec

@github-actions
Copy link

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 Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants