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

No checks for array_map closure params #1954

Closed
muglug opened this issue Mar 4, 2019 · 4 comments
Closed

No checks for array_map closure params #1954

muglug opened this issue Mar 4, 2019 · 4 comments

Comments

@muglug
Copy link
Contributor

muglug commented Mar 4, 2019

<?php declare(strict_types = 1);

$a = [1, new stdClass()];
$b = array_map(function (string $s) : string { return $s; }, $a);

Expected: argument passed to first arg of array_map is wrong
Actual: No issues

https://phpstan.org/r/15291a0f-d267-4eec-87d3-61ef0803df57

Would have flagged this code:

$actualErrors = array_map(
static function (Error $error): string {
return sprintf('%02d: %s', $error->getLine(), $error->getMessage());
},
$actualErrors
);

which expects is passed string[]|\PHPStan\Analyser\Error[]

@ondrejmirtes
Copy link
Member

Yeah, I plan to support this once generics are implemented.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-No errors
+4: Parameter #1 $callback of function array_map expects callable(1|stdClass): mixed, Closure(string): string given.
Full report
Line Error
4 `Parameter #1 $callback of function array_map expects callable(1

@muglug
Copy link
Contributor Author

muglug commented Sep 12, 2021

Looks fixed now!

@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.
Projects
None yet
Development

No branches or pull requests

3 participants