Home » PEAR » PEAR » Bug #9101
PEAR_Exception::getCauseMessage() failure with a nested Exception
Details
| Submitted | 2006-10-20 07:25 UTC |
|---|---|
| From | aharvey at optimiser dot com |
| Assigned | cellog |
| Status | Closed |
| Package | PEAR |
| PHP Version | 5_2 CVS-2006-10-20 |
| OS | Linux (Ubuntu 6.06) |
| Roadmaps | (Not assigned) |
Comments
[2006-10-20 07:25 UTC] aharvey at optimiser dot com
Description:
------------
PEAR_Exception::__toString() throws a fatal error when the PEAR_Exception has a nested Exception. Note that a nested PEAR_Exception works, the failure only occurs when the nested exception inherits from Exception but not PEAR_Exception.
Test script:
---------------
<?php
require_once 'PEAR/Exception.php';
try {
throw new PEAR_Exception('Test exception.', new Exception('Nested exception.'));
} catch (PEAR_Exception $e) {
echo $e->__toString()."\n";
}
?>
The patch at http://www.adamharvey.name/patches/PEAR_Exception-getCauseMessage.patch seems to fix the problem, but not being an expert on PEAR's internals, I don't know if that's actually the right solution.
Expected result:
----------------
PEAR_Exception: Test exception. in /tmp/exception.php on line 7
Exception: Nested exception. in /tmp/exception.php on line 5
#0 {main}
Actual result:
--------------
Fatal error: Call to a member function getMessage() on a non-object in /usr/share/pear/PEAR/Exception.php on line 246
Call Stack:
0.0004 1. {main}() /tmp/exception.php:0
0.0028 2. PEAR_Exception->__toString() /tmp/exception.php:7
0.0028 3. PEAR_Exception->toText() /usr/share/pear/PEAR/Exception.php:305
0.0028 4. PEAR_Exception->getCauseMessage() /usr/share/pear/PEAR/Exception.php:365