Bug #70967 [Com]: Weird error handling for __toString when Error is thrown
| From: | shiranai7 at hotmail dot com | Date: | Sun, 29 Nov 2015 02:09:36 +0000 |
| Subject: | Bug #70967 [Com]: Weird error handling for __toString when Error is thrown | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-197479@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
Comment by: shiranai7 at hotmail dot com
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
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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