*Please change the title into something that refer into this question since i didn't know what is this should be.
When i read some tutorial i see script like this
function testArray(array $categories) {
var_dump($categories);
}
testArray(array('string'));
The array in function definition make the parameter strict must be array, which i love it.
Then i test this script
function testString(string $string) {
var_dump($string);
}
testString('test');
Why did i get error like this Catchable fatal error: Argument 1 passed to testString() must be an instance of string, string given ....?
I'm pretty sure the parameter is string.
You are talking about Type Hinting. PHP type hinting can only be used in objects and arrays. String is a scalar type which does not supports type hinting
More on type hinting
http://php.net/manual/en/language.oop5.typehinting.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With