Bug #70967 [Opn]: Weird error handling for __toString when Error is thrown
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
Block user comment: N
Private report: N
New Comment:
hmm, then what should it says? must not throw anything? :)
Previous Comments:
------------------------------------------------------------------------
[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
Thread (6 messages)