PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » PEAR » PEAR » Bug #9101

PEAR_Exception::getCauseMessage() failure with a nested Exception

Details

Submitted2006-10-20 07:25 UTC
Fromaharvey at optimiser dot com
Assignedcellog
StatusClosed
PackagePEAR
PHP Version5_2 CVS-2006-10-20
OSLinux (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