PHP7中異常與錯誤處理與之前版本對比
10年的舒城網(wǎng)站建設經(jīng)驗,針對設計、前端、開發(fā)、售后、文案、推廣等六對一服務,響應快,48小時及時工作處理。成都全網(wǎng)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設備顯示端的尺寸不同,自動調(diào)整舒城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“舒城網(wǎng)站設計”,“舒城網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。先上代碼
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