function foo (string $s) { echo $s;} Foo ("Hello World");
Error catchable fatal error:argument 1 passed to Foo () must is an instance of string, string given, called in
Why is this? How should I write it?
Reply to discussion (solution)
Type constraints are actually a setback
Type constraints only support objects and arrays of two types. Integer and string types are not supported.
PHP is weak type is not supported for simple types, generally supports object and array
PHP function declaration parameter does not need to specify type
settings.php
False
addressmanager.php
Class addressmanager{
Private $addresses = Array ("209.131.36.159", "74.125.19.106");
function Outputaddresses ($resolve) {
foreach ($this->addresses as $address) {
if (!is_bool ($resolve)) {
Die ("outputadresses () requires a Boolean argument\n");
}
Print "
";
}
}
}
$settings = simplexml_load_file ("settings.xml");
$manager = new Addressmanager ();
$manager->outputaddresses (String) $settings->resolvedomains);
But here $manager->outputaddresses ((string) $settings->resolvedomains), the type constraint is yes
Well, it's very
Thank you