The X argument passed to Y must be an instance of boolean, boolean data - PHP7
This code
<?php
function a(boolean $value){
var_dump($value);
}
a(true);
I am getting the error
TypeError: argument 1 passed to () must be an instance of boolean, boolean data
What's going on here?
Only valid typehint for boolean
- bool
. According to the documentation it is boolean
not recognized as an alias bool
in types. Instead, it is treated as a class name. The same goes for int
(scalar) and integer
(class name) which will result in an error
TypeError: Argument 1 passed to () must be an integer instance, integer given
In this particular case, a class object is expected boolean
, but passed in true
(bool, scalar).
Valid code
<?php
function a(bool $value){
var_dump($value);
}
a(true);
get
BOOL (true)