ID:               34538
 User updated by:  ts at siteartwork dot de
 Reported By:      ts at siteartwork dot de
 Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      5.*
 Assigned To:      helly
 New Comment:

>Thank you for taking the time to write to us, but this is >not
I did mark it as a feature-request, so I thought it would be okay.

>[...]

I've seen this concept in other languages (the need to wrap another
exception to "assimilate" it) but I know that the howto of exceptions
are often discussed, so I won't argue and accept your decision. Thx for
your reply!


Previous Comments:
------------------------------------------------------------------------

[2005-09-18 13:16:20] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Exceptions are write once (constructor) and read multiple (access
methods). This is necessary because a missuse might otherwise most
likely result in an immediate SEGV or even worse a security issue.

But anyway is the need to overwrite information passed along with an
exception a sign for a design flaw. Exceptions are not meant to
transport parameters. In general follow these rules:
1) Exceptions are Exceptions
2) Never Exceptions for control flow
3) Never ever use Exceptions for parameter passing


------------------------------------------------------------------------

[2005-09-17 18:40:01] ts at siteartwork dot de

Description:
------------
The declaration of getMessage() as final in the SPLs Exception class
makes it impossible to encapsulate other (Userland-)Exceptions and
provide appropriate functionality.


Reproduce code:
---------------
<?php

class UserException extends Exception {

private $encapsulatedException = null;

public function __construct($message = null, $e = null)
{
    if ($e !== null && ($e instanceof Exception) {
    $this->encapsulatedException = $e;
    } else {
   $this->encapsulatedException = null;
 
}
    parent::__construct($message);
}

public function getMessage()
{
   $message = parent::getMessage();
    if ($message == null && $this->encapsulatedException !== null) {
    echo $this->encapsulatedException->getMessage();
}
}

}

?>

Expected result:
----------------
It should be possible to override the getMessage()-method to decide
wether to return the message the object was instantiated with or the
message of the encapsulated Exception.

Actual result:
--------------
Fatal error: Cannot override final method Exception::getMessage() 


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=34538&edit=1

Reply via email to