When you run the following code:
function foo(string $text) {
echo $text;
}
foo('bar');
I get the following error:
PHP Catchable fatal error: Argument 1 passed to foo () must be an instance of string, given string, called in / home /...
I was intrigued because I had never done it before with Strings
, I always did with Array
, and it worked.
Question
The error occurred because the method called for an instance of string
, but 'bar'
is not an instance of string
? If 'bar'
is not an instance of string
, what parameter should I put in order for this function to execute correctly?
I think this error should be better explained.