Re: [PHP-DEV] asString() method vs __toString() magic method.

2011-08-06 Thread Richard Quadling
On 3 August 2011 00:51, Stas Malyshev wrote: > Hi! > > On 8/2/11 7:51 AM, Etienne Kneuss wrote: >> >> The (historic) reason is that the toString conversion occurs at >> various places in the engine, and in some of them, throwing exceptions >> caused trouble. It is not clear whether this limitation

Re: [PHP-DEV] asString() method vs __toString() magic method.

2011-08-02 Thread Stas Malyshev
Hi! On 8/2/11 7:51 AM, Etienne Kneuss wrote: The (historic) reason is that the toString conversion occurs at various places in the engine, and in some of them, throwing exceptions caused trouble. It is not clear whether this limitation it still required. In any case, it could almost certainly be

Re: [PHP-DEV] asString() method vs __toString() magic method.

2011-08-02 Thread Ferenc Kovacs
On Tue, Aug 2, 2011 at 4:47 PM, Richard Quadling wrote: > Hi. > > Given the relatively simple code below, why can't I throw an exception > in __toString()? > > class AlwaysFails { >  public function asString() { >    throw new Exception('Failed in asString()'); >  } > >  public function __toStrin

Re: [PHP-DEV] asString() method vs __toString() magic method.

2011-08-02 Thread Richard Quadling
On 2 August 2011 16:09, Keloran wrote: > i didnt think any of the magic functions could throw exceptions All magic methods can throw exceptions except __toString. There is some oddity with __set_state() (in terms of the pattern of output is different). http://pastebin.com/nGkP7kKf outputs ...

Re: [PHP-DEV] asString() method vs __toString() magic method.

2011-08-02 Thread Etienne Kneuss
Hello, On Tue, Aug 2, 2011 at 16:47, Richard Quadling wrote: > Hi. > > Given the relatively simple code below, why can't I throw an exception > in __toString()? The (historic) reason is that the toString conversion occurs at various places in the engine, and in some of them, throwing exceptions

[PHP-DEV] asString() method vs __toString() magic method.

2011-08-02 Thread Richard Quadling
Hi. Given the relatively simple code below, why can't I throw an exception in __toString()? asString(); } catch(Exception $ex) { echo $ex->getMessage(); } try { echo $failure; } catch(Exception $ex) { echo $ex->getMessage(); } ?> outputs ... Failed in asString() Fatal error: Method Alway