Why it's impossible to throw exception from __toString()?

后端 未结 6 1903
半阙折子戏
半阙折子戏 2020-12-29 18:33

Why it\'s impossible to throw exception from __toString()?

class a
{
    public function __toString()
    {
        throw new Exception();
    }
}

$a = new          


        
6条回答
  •  渐次进展
    2020-12-29 18:51

    My guess would be that __toString is hackish and therefore exists outside of the typical stack. A thrown exception, then, wouldn't know where to go.

提交回复
热议问题