令人惊讶的是,我无法在Google或SO上找到任何相关信息.当我在PHP中抛出异常时,它会在我的控制台中出现两次,完成错误消息和堆栈跟踪.它第一次打印出来时说"PHP Fatal error:...",第二次它只是说"致命错误:......".我没有测试过这是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)(内置:2012年1月11日17:09:48)
版权所有(c)1997-2012 PHP Group 
Zend Engine v2.3.0,版权所有(c)1998-2012 Zend Technologies
http://pastebin.com/iBUGJ2eY
 
这是为我显示双重例外的确切代码,命名空间和路径编辑为foos.请注意,我总是在此安装的命令行中获得双重例外.我几乎可以肯定,问题在于PHP配置.
Lin*_*een 36
得到了再现.第一条错误消息是log_errors设置的结果并转到STDERR.
第二个是结果,display_errors然后去STDOUT.
这两个设置都可以在运行时更改.所以为了"很好地问问PHP",这就足够了:
ini_set('log_errors', 1);
ini_set('display_errors', 0);