You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function someFunction accepts a parameter $callback with the type (callable(int):mixed)|string|null. However, when passing 'myFunc' (a name of almost any function) as an argument, a InvalidArgument error occurs.
Happened to me with PHP 8.3, Psalm 5.26.1, in Laravel Eloquent (v11).
I tried to aggregate metrics. count is the field of object with count of requests
<?php/** * Get the max value of a given key. * * @param (callable(int):mixed)|string|null $callback * @return mixed */functionsomeFunction(callable|string|null$callback): callable|string|null
{
return$callback;
}
/** * @param array $value The array or the object. * @param int $mode [optional] If the optional mode parameter is set to*/functionmyFunc(array$value, int$mode = COUNT_NORMAL): int {
returncount($value)*$mode; //just to suppress UnusedParameter
}
someFunction('myFunc'); // <- this is valid parameter with type 'string' but InvalidArgument appeared, no oksomeFunction((string)'myFunc'); // <- no InvalidArgument
Psalm output (using commit 765dcbf):
ERROR: InvalidArgument - 22:14 - Argument 1 of someFunction expects callable(int):mixed|null|string, but impure-callable(array<array-key, mixed>, int=):int provided
ERROR: RedundantCast - 23:14 - Redundant cast to string
The function
someFunction
accepts a parameter $callback with the type (callable(int):mixed)|string|null. However, when passing 'myFunc' (a name of almost any function) as an argument, a InvalidArgument error occurs.https://psalm.dev/r/b0184be10a
Happened to me with PHP 8.3, Psalm 5.26.1, in Laravel Eloquent (v11).
I tried to aggregate metrics.
count
is the field of object with count of requestsThe text was updated successfully, but these errors were encountered: