php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62420 Exception::__toString() creates message in wrong order if prev exception exists
Submitted: 2012-06-26 11:56 UTC Modified: 2012-07-25 14:11 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: bugs dot php at mohiva dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.4.4 OS: Gentoo Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-06-26 11:56 UTC] bugs dot php at mohiva dot com
Description:
------------
The method Exception::__toString() creates the message in the wrong order if a previous exception exists in the Exception object.

The message contains the message from the previous exception as first and then marked as next exception the message from the exception object itself. Normally the message from the current exception should be the first message followed by the previous message and so one.

Test script:
---------------
<?php

try {
    throw new Exception("Previous exception");
} catch (Exception $previous) {
    $current = new Exception("Current exception", 0, $previous);

    echo 'Previous:' . $current->getPrevious()->getMessage() . '<br />';
    echo 'Current:' . $current->getMessage() . '<br />';
    echo 'String:' . $current->__toString() . '<br />';
}


Expected result:
----------------
Previous: Previous exception
--------------------------------------------------------------
Current: Current exception
--------------------------------------------------------------
String: exception 'Exception' with message 'Current exception' in exception.php:4 Stack trace: #0 {main} Next exception 'Exception' with message 'Previous exception' in exception.php:6 Stack trace: #0 {main}

Actual result:
--------------
Previous: Previous exception
--------------------------------------------------------------
Current: Current exception
--------------------------------------------------------------
String: exception 'Exception' with message 'Previous exception' in exception.php:4 Stack trace: #0 {main} Next exception 'Exception' with message 'Current exception' in exception.php:6 Stack trace: #0 {main}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-24 08:28 UTC] fa@php.net
While you are correct that it might be more logical to reverse the order, this 
isn't a huge problem.
 [2012-07-24 08:28 UTC] fa@php.net
-Status: Open +Status: Wont fix
 [2012-07-25 14:11 UTC] bugs dot php at mohiva dot com
I think with this behaviour it is really hard to find bugs and it has a huge WTF factor when you look into your log files and then you see the exception messages in a reverse order.

Is it really too hard to fix?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 21:01:29 2024 UTC