Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置\异常\处理程序不能与PHP CLI一起使用?_Php_Exception_Exception Handling_Command Line Interface - Fatal编程技术网

设置\异常\处理程序不能与PHP CLI一起使用?

设置\异常\处理程序不能与PHP CLI一起使用?,php,exception,exception-handling,command-line-interface,Php,Exception,Exception Handling,Command Line Interface,我在php文档中遗漏了什么吗 我在我的index.php上设置了set\u exception\u处理程序,以捕获异常(来自libraries),并避免未捕获异常的php致命错误 当我用Apache运行我的脚本时,我没有问题(捕获异常的函数工作正常)。 但是当我尝试使用PHPCLI(PHP-r'include“index.PHP”;)时,我得到了PHP致命错误 有什么想法吗 --index.php set_exception_handler('exception_handler'); throw

我在php文档中遗漏了什么吗

我在我的
index.php
上设置了
set\u exception\u处理程序,以捕获异常(来自libraries),并避免未捕获异常的php致命错误

当我用Apache运行我的脚本时,我没有问题(捕获异常的函数工作正常)。 但是当我尝试使用PHPCLI(
PHP-r'include“index.PHP”;
)时,我得到了PHP致命错误

有什么想法吗

--index.php

set_exception_handler('exception_handler');
throw new Exception("Test exception");

function exception_handler($e) {
    echo '-- excemption handler --';
    $toLog = '['.date('d/m/Y H:i:s').'] '.$e->getMessage()."\n".$e->getTraceAsString();
    var_dump($toLog);
}

要运行代码,您应该使用

php index.php

set_exception_handler('exception_handler');
throw new Exception("Test exception");

function exception_handler($e) {
    echo '-- excemption handler --';
    $toLog = '['.date('d/m/Y H:i:s').'] '.$e->getMessage()."\n".$e->getTraceAsString();
    var_dump($toLog);
}
这不会显示致命错误

当你跑步的时候

php-r'包括“index.php”;'


它实际上是以php脚本的形式执行语句。这个脚本本身不需要处理它自己的致命错误。

如何显示您的代码?这是一个非常奇怪的问题,它会影响偶尔使用
php-r
测试代码片段的人。看起来像一个bug。是的,没有更多的错误,但在我的脚本中,我需要将var传递给index.php。。。这就是为什么我使用
php-r
。我可以尝试用另一种方式传递我的var(比如
php index.php args
)。