Bug #70967 [Opn]: Weird error handling for __toString when Error is thrown

From: Date: Wed, 25 Nov 2015 09:33:32 +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-197411@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
 Block user comment: N
 Private report:     N

 New Comment:

okey , I understand it now.. but I am not sure how to fix it is better :<


Previous Comments:
------------------------------------------------------------------------
[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


Thread (6 messages)

« previous php.bugs (#197411) next »