Summary
Amazingly I could find nothing about this on Google or SO. When I throw an exception in PHP it appears in my console twice, complete with error message and stack trace. The first time it’s printed it says “PHP Fatal error: …” and the second time it just says “Fatal error: …”. I haven’t tested this is the Apache plugin version.
Example
With some namespaces and paths shortened with ‘…’ for safety:
$ 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
Question
I assume it has something to do with stderr and stdout both printing the error. In any case how do I ask PHP nicely to only print it once, preferably to stderr?
Version output
PHP 5.3.9 (cli) (built: Jan 11 2012 17:09:48)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
The code
http://pastebin.com/iBUGJ2eY
This is the exact code that displays double exceptions for me, with namespaces and paths edited to foos. Note that I always get double exceptions in the command line on this installation. I’m all but certain that the issue lies in the PHP configuration.
Related posts:
- Throwing exception within exception handler I have a script with an exception handler. This exception handler cleans up a couple...
- How can I get PHP to produce a backtrace upon errors? Trying to debug PHP using its default current-line-only error messages is horrible. How can I...
- Try/Catch block in PHP not catching Exception I am trying to run Example #1 from this page: http://php.net/manual/en/language.exceptions.php However instead of the...
- Error on creating connection to PDO in PHP Today, I removed and reinstalled the latest version of lampp in order to move to...
- ImageMagick/Imagick convert PDF to JPG using native PHP API I’m attempting to convert PDF files into PNGs. It works great from the command line...
- Why does PDO print my password when the connection fails? I have a simple website where I establish a connection to a Mysql server using...
- PHP: exceptions vs errors? Maybe I’m missing it somewhere in the PHP manual, but what exactly is the difference...
- How to implement exception chaining in PHP Constructor for PHP’s exception has third parameter, documentation says: $previous: The previous exception used for...
- trying to send mail using swift mailer, gmail smtp, php Here is my code: <?php require_once 'Swift/lib/swift_required.php'; $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465) ->setUsername('me@ff.com') ->setPassword('pass'); $mailer =...
- Non PHP site generates PHP errors I have this error appearing: Parse error: syntax error, unexpected T_STRING in /home/ondesign/public_html/ywamleicester.org/index.html on line...





