|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-09-18 13:16 UTC] helly@php.net
[2005-09-18 14:38 UTC] ts at siteartwork dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 13 16:00:01 2025 UTC |
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()