Bug #70967 [Opn]: Weird error handling for __toString when Error is thrown
| From: | laruence@php.net | Date: | Sun, 29 Nov 2015 03:50:03 +0000 |
| Subject: | Bug #70967 [Opn]: Weird error handling for __toString when Error is thrown | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197483@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70967&edit=1
ID: 70967
Updated by: laruence@php.net
Reported by: bugs dot php dot net at majkl578 dot cz
Summary: Weird error handling for __toString when Error is
thrown
Status: Open
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.0.0RC7
-Assigned To:
+Assigned To: laruence
Block user comment: N
Private report: N
New Comment:
hmm, okey, let me think about it
Previous Comments:
------------------------------------------------------------------------
[2015-11-29 02:09:34] shiranai7 at hotmail dot com
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
------------------------------------------------------------------------
[2015-11-25 09:33:31] laruence@php.net
okey , I understand it now.. but I am not sure how to fix it is better :<
------------------------------------------------------------------------
[2015-11-25 05:13:58] laruence@php.net
hmm, then what should it says? must not throw anything? :)
------------------------------------------------------------------------
[2015-11-25 02:39:50] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70967&edit=1