为什么不可能从__toString()中引发异常?
为什么不可能从__toString()中引发异常?
class a
{
public function __toString()
{
throw new Exception();
}
}
$a = new a();
echo $a;
上面的代码产生这样的结果:
Fatal error: Method a::__toString() must not throw an exception in /var/www/localhost/htdocs/index.php on line 12
我被指向描述这种行为 http://php.net/manual/en/migration52.incompatible.php,但为什么呢?有什么理由这样做吗?
也许这里有人知道这一点?
在 bug 跟踪器 php-dev-team 像往常一样什么也没说,但看到手册:http://bugs.php.net/50699