1

Is there any way to pass parameters in doc from callable to function baz $params? I need give parameters in array associated by its names.

interface Bar {

    /**
     * @template TResult of mixed
     * @template TParam of mixed
     *
     * @param callable(TParam...):TResult $callable
     * @param array<array-key,TParam>     $params
     *
     * @return TResult
     */
    public function baz( callable $callable, array $params ): mixed;

}
/** @var Bar $bar */
$bar = '...';

$bar->baz(
    fn( int $a, float $b, ?bool $c = null ) => $a, // phpstan error here 
    [ 'a' => 1, 'b' => .1, 'c' => null ]
);
phpstan error: phpstan: Parameter #1 $callable of method Bar::baz() expects callable(float|int|null ...): int, Closure(int, float, bool|null=): int given.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.