Code Inspection: Function call is not compatible with 'callable' declaration
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports the parameters in function calls whose types are not compatible with the ones defined via Closure
.
In the following example, the Closure
annotation indicates that a returned function expects two integer
parameters, while the function call is erroneously provided with the array
argument.
/**
* @return Closure(int, int) : int
*/
function delayedAdd(): Closure {
return function($a, $b) {
return $a + $b;
};
}
$numbers = [1, 2];
$adder = delayedAdd();
echo $adder($numbers, 5);
Place the caret at the highlighted line and press AltEnter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.