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