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

False positive: array_walk should be working also with objects #6338

Closed
niconoe- opened this issue Aug 19, 2021 · 3 comments · Fixed by #6339
Closed

False positive: array_walk should be working also with objects #6338

niconoe- opened this issue Aug 19, 2021 · 3 comments · Fixed by #6339

Comments

@niconoe-
Copy link

Hi there!

I noticed some weeks ago that PHP is allowing objects in array_walk and array_walk_recursive internal functions.

Therefore, the error InvalidArgument - file.php:line:col - Argument 1 of array_walk expects array<array-key, mixed>, stdClass provided should not be triggered.
See: https://psalm.dev/r/0aeeb09741

I already helped in providing a PR for PHPStan which had the same issue as yours: phpstan/phpstan-src#573. The PR was incomplete but still, the feature to allow objects in such function was accepted

I don't know yet how you're referencing internal PHP functions, but if this is something like PHPStan, I could probably provide you a PR for that.

Have a nice day.
Regards,

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/0aeeb09741
<?php

$foo = (object)['index' => 'value', 'key' => 'value'];
array_walk($foo, 'strlen');
Psalm output (using commit 9e1f7ad):

ERROR: InvalidArgument - 4:12 - Argument 1 of array_walk expects array<array-key, mixed>, stdClass provided

@orklah
Copy link
Collaborator

orklah commented Aug 19, 2021

Hey!

Please check this directory: https://github.com/vimeo/psalm/tree/master/dictionaries

This should feel similar to PHPStan in that regard.

@niconoe-
Copy link
Author

Yup, I found this out 😄

Problem is this file is too big to be edited via GitHub WebIDE so I can't propose a PR fastly. I need to do it in the old fashion way by cloning a fork...
I'm trying to provide something currently.

Please be aware that for PHPStan, it didn't entierly solved the issue as the mechanics never worked with union type array|object before. Is your mechanic a little bit more generic and only changing the callmap will be enough?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants