类型提示在字符串的情况下不起作用。
function def_arg(int $name, int $address, string $test){
return $name . $address . $test;
}
echo def_arg(3, 4, 10) ;
// It doesn't throws an error as expected.
另一方面。如果你在第一个参数中给出字符串,它会抛出一个错误,说它应该是一个 int。
function def_arg(int $name, int $address, string $test){
return $name . $address . $test;
}
echo def_arg("any text", 4, "abc") ;
// this code throws an error
// "Fatal error: Uncaught TypeError: Argument 1 passed to def_arg() must be of the type integer, string given,"
为什么在字符串的情况下没有错误?