鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ 為何lumen框架中的undefined index錯誤會拋出異常?

為何lumen框架中的undefined index錯誤會拋出異常?

<?php
    $a = array();
    $b = $a['test'];
?>

以上代碼單獨執(zhí)行時只會報:PHP Notice: Undefined index: test in /private/var/folders/lr/hbwptx4s1017kl_hlr4d9b4r0000gn/T/CodeRunner/Untitled.php on line 3

但是在lumen框架中卻會拋出一個ErrorException異常:

(1/1) ErrorException
Undefined index: test

in ExampleController.php (line 23)
at Application->Laravel\Lumen\Concerns\{closure}(8, 'Undefined index: test', '/Users/kai/work/api/app/Http/Controllers/ExampleController.php', 23, array())
in ExampleController.php (line 23)
at ExampleController->testOrder()
at call_user_func_array(array(object(ExampleController), 'testOrder'), array())
in BoundMethod.php (line 29)
回答
編輯回答
不舍棄

因為設(shè)置了: error_reporting(-1);,然后用set_error_handler處理錯誤,在處理的時候拋出異常。

相關(guān)代碼在IlluminateFoundationBootstrapHandleExceptions::bootstrap

2017年1月10日 04:34