为什么 PHP 错误打印两次?
总结
令人惊讶的是,我在Google或SO上找不到任何关于此的内容。当我在PHP中抛出异常时,它会在我的控制台中出现两次,并带有错误消息和堆栈跟踪。第一次打印时,它说“PHP致命错误:...”第二次它只是说“致命错误:...”。我还没有测试这是Apache插件版本。
例
使用一些命名空间和路径缩短为“...”为了安全:
$ php code/com/.../tabular_data.php PHP Fatal error: Uncaught exception 'Exception' with message 'File type not supported' in /home/codemonkey/.../tabular_data.php:56 Stack trace: #0 /home/codemonkey/.../tabular_data.php(88): com\...\Tabular_Data->loadFromFile('/home/codemonke...', false) #1 /home/codemonkey/.../tabular_data.php(95): com\...\Tabular_Data::fromFile('/home/codemonke...') #2 {main} thrown in /home/codemonkey/.../tabular_data.php on line 56 Fatal error: Uncaught exception 'Exception' with message 'File type not supported' in /home/codemonkey/.../tabular_data.php:56 Stack trace: #0 /home/codemonkey/.../tabular_data.php(88): com\...\Tabular_Data->loadFromFile('/home/codemonke...', false) #1 /home/codemonkey/.../tabular_data.php(95): com\...\Tabular_Data::fromFile('/home/codemonke...') #2 {main} thrown in /home/codemonkey/.../tabular_data.php on line 56
问题
我认为它与stderr和stdout都打印错误有关。无论如何,我如何要求PHP只打印一次,最好是stderr?
版本输出
PHP 5.3.9 (cli) (已建設: Jan 11 2012 17:09:48)
Copyright (c) 1997-2012 PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
代码
http://pastebin.com/iBUGJ2eY 这是为我显示双重异常的确切代码,命名空间和路径已编辑为foos。请注意,在此安装中,我总是在命令行中收到双重异常。我几乎可以肯定,问题在于PHP配置。