是否有可能在php中使用try / catch在eval中

时间:2020-01-21 15:49:10

标签: php

你好,我试图在eval()函数内的php中使用 try / catch 吗? 我尝试了一些测试,但没有发现异常。

2 个答案:

答案 0 :(得分:0)

确定是...

eval('

    try {
        throw new Exception;
    } catch(Exception $e) {
        var_dump($e);
    }

');

该代码将产生以下输出...

object(Exception)#1 (7) {
  ["message":protected]=>
  string(0) ""
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(28) "/in/aqFQZ(3) : eval()'d code"
  ["line":protected]=>
  int(3)
  ["trace":"Exception":private]=>
  array(1) {
    [0]=>
    array(3) {
      ["file"]=>
      string(9) "/in/aqFQZ"
      ["line"]=>
      int(3)
      ["function"]=>
      string(4) "eval"
    }
  }
  ["previous":"Exception":private]=>
  NULL
}

答案 1 :(得分:0)

准备使用 mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

相关问题