Req #53648 [Sus->Opn]: Allow __toString() to throw exceptions
| From: | aharvey@php.net | Date: | Wed, 27 May 2015 17:01:58 +0000 |
| Subject: | Req #53648 [Sus->Opn]: Allow __toString() to throw exceptions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-192921@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53648&edit=1
ID: 53648
Updated by: aharvey@php.net
Reported by: clicky at erebot dot net
Summary: Allow __toString() to throw exceptions
-Status: Suspended
+Status: Open
Type: Feature/Change Request
Package: Class/Object related
PHP Version: 5.3.4
Block user comment: N
Private report: N
New Comment:
Reopening, although this will require an RFC (and, realistically, a PR) to proceed against a later
7.x version.
Previous Comments:
------------------------------------------------------------------------
[2015-03-29 09:41:48] benjamin dot morel at gmail dot com
Note that, for what it's worth, starting from version 3.4.1, HHVM allows __toString() to throw
exceptions:
http://3v4l.org/jFfUh
Do notice also that miraculously, PHP 5.0 and 5.1 did allow __toString() to throw exceptions! How is
that even possible?
------------------------------------------------------------------------
[2015-03-29 09:31:46] benjamin dot morel at gmail dot com
Now would be the time indeed! Could a core developer comment on this issue?
------------------------------------------------------------------------
[2015-03-14 19:46:39] ianbytchek at gmail dot com
Any chance to account for this in PHP 7? I've read that many things in the core are being
re-written / -factored. Would now be the right time to look into this?
------------------------------------------------------------------------
[2014-09-08 09:25:28] benjamin dot morel at gmail dot com
By the way, it's interesting to note that calling __toString() manually works fine:
class A {
public function __toString() {
throw new Exception();
}
}
echo (new A); // fatal error
echo (new A)->__toString(); // exception
Still no news on that issue, 2 years later? It's a very big blocking issue for doing
interesting things in modern frameworks.
------------------------------------------------------------------------
[2012-12-05 01:13:22] aharvey@php.net
Suspending: as Stas explained in the linked e-mail thread, it's "pretty hard" to do
in the current engine.
Should there ever be a Zend Engine 3, however, this could be revisited.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=53648
--
Edit this bug report at https://bugs.php.net/bug.php?id=53648&edit=1