爲什麼我不能傳遞一個返回字符串的函數作爲函數的參數,其中參數的類型是string?爲什麼我不能傳遞一個返回字符串的函數作爲函數的參數,其中參數的類型是string?
例如:
function testFunction(string $strInput) {
// Other code here...
return $strInput;
}
$url1 = 'http://www.domain.com/dir1/dir2/dir3?key=value';
testFunction(parse_url($url1, PHP_URL_PATH));
上面的代碼返回一個錯誤:
Catchable fatal error: Argument 1 passed to testFunction() must be an instance of string...
我怎樣才能做到這一點?
PHP是使用Javascript風格聲明變量時,不需要你來聲明一個變量類型鬆散類型的語言。 – 2013-03-22 01:25:28
除了你的類型暗示的問題,你應該注意到parse_url返回一個數組,你似乎期待一個字符串。 – Jeemusu 2013-03-22 01:33:21
你並不孤單:http://yatb.giacomodrago.com/en/post/1/php-is-not-easy-as-it-may-seem.html,告誡4 – gd1 2013-03-22 01:48:23