#50699 [Bgs]: Cannot throw Exceptions in __toString()
| From: | gmblar+php at gmail dot com | Date: | Fri, 08 Jan 2010 22:51:47 +0000 |
| Subject: | #50699 [Bgs]: Cannot throw Exceptions in __toString() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-146461@lists.php.net to get a copy of this message | ||
ID: 50699
User updated by: gmblar+php at gmail dot com
Reported By: gmblar+php at gmail dot com
Status: Bogus
Bug Type: *General Issues
Operating System: *
PHP Version: 5.3.1
New Comment:
Current behavior of __toString is crap. Why i can use trigger_error()
bug not throw Exception() in __toString()? Please fix it.
Previous Comments:
------------------------------------------------------------------------
[2010-01-08 22:24:09] bjori@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
__toString() must not throw exceptions
------------------------------------------------------------------------
[2010-01-08 22:22:35] gmblar+php at gmail dot com
Description:
------------
Cannot throw Exceptions in __toString(). Instead it produces a Fatal
error.
Reproduce code:
---------------
<?php
class bar {
public function __toString() {
throw new Exception('Incomplete Data');
}
}
$foo = new bar();
echo $foo;
?>
Expected result:
----------------
Fatal error: Uncaught exception 'Exception' with message 'Incomplete
Data' in /-:6
Actual result:
--------------
Fatal error: Method bar::__toString() must not throw an exception in /-
on line 0
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50699&edit=1