PHP7中異常與錯誤處理與之前版本對比
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:國際域名空間、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、五家渠網(wǎng)站維護、網(wǎng)站推廣。
先上代碼
ECHO PHP_VERSION.PHP_EOL; function add (int $left,int $right){ return $left+$right; } try { echo add('left', 'right'); } catch (Exception $e) { // Handle exception } catch (Error $e) { // Clearly a different type of object // Log error and end gracefully var_dump($e->getMessage()); } echo PHP_EOL."helloword".PHP_EOL;
PHP v5.6.1結(jié)果
5.6.1 PHP Catchable fatal error: Argument 1 passed to add() must be an instance of int, string given, called in C:\usertb\shareubuntu\Workerman\fortest.php on line 8 and defined in C:\usertb\shareubuntu\Workerman\fortest.php on line 3 Catchable fatal error: Argument 1 passed to add() must be an instance of int, string given, called in C:\usertb\shareubuntu\Workerman\fortest.php on line 8 and defined in C:\usertb\shareubuntu\Workerman\fortest.php on line 3 [Finished in 0.0s]
PHP v7.0.15結(jié)果
7.0.15-0ubuntu0.16.04.4 string(131) "Argument 1 passed to add() must be of the type integer, string given, called in /home/tb/win10share/Workerman/fortest.php on line 8" helloword
區(qū)別
在于后者可以捕獲fatal error,并且可以正常輸出helloword