Argument #%d ($%s) must be of type %s, %s given¶
Description¶
This error is emitted when data of a wrong type is given to a typed argument.
The first parameter that fails the type constraint is reported. There might be other type failures after this one, though they are hidden by the first one encountered.
Example¶
<?php
function foo(int $x) {}
foo(1); // OK
foo('2'); // OK, with strict_types = 0
foo('abc'); // not OK
?>
Literal Examples¶
Argument #1 ($x) must be of type int, string given
Solutions¶
Pass the correct argument to the method.
Cast the value to the requested type.
Change the type in the signature of the called method.
Add the type in the signature of the called method.