|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-11-25 02:39 UTC] bugs dot php dot net at majkl578 dot cz
Description:
------------
When an error occurs inside __toString method, for example call to an undefined function, an Error is thrown. But since __toString does not allow exceptions to be thrown from inside, it just says "__toString() must not throw an exception".
This behavior is especially confusing e.g. in case of a typo (see below).
Test script:
---------------
<?php
echo new class {
function __toString() {
return stravl(123); // should be strval
}
};
Expected result:
----------------
Something more accurate, either the message of the Error itself or at least better generic message.
Actual result:
--------------
Fatal error: Method class@anonymous::__toString() must not throw an exception
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 16:00:01 2025 UTC |
Doesn't zend_std_cast_object_tostring() have access to the exception object? If it does, the exception's message and stack trace could be appended to the fatal error's message. (This is already the default behavior for uncaught exceptions). Example: Method FooBar::__toString() must not throw an exception. Uncaught exception 'Exception' with message 'BLAH' in SOMEFILE:123 Stack trace: #0 {main} thrown in SOMEFILE on line 123