をスローリターン偽:代わりに、私はこの機能を持っている例外
public static function get($action, $param = null) {
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => "GET"
)
);
$context = stream_context_create($options);
$params = '';
foreach($param as $key => $value)
$params .= $key . '=' . $value . '&';
trim($params, '&');
$result = file_get_contents(self::$url . $action . '?' . $params, false, $context);
return json_decode($result, true);
}
問題がある:私はfile_get_contents
に間違ったURLを提供する場合、それはエラー(例外)を投げます。 しかし、私はスローエラーなしで代わりにfalseを返したいと思います。 どうすればいいですか?
その行内でcatchブロックを試してください – ashish