> Hi Benjamin.

 

Hi Janub,

 

> I have a question: is there any reason to throw an exception from __toString, 
> other than a non-recoverable error, which would denote that the object, which 
> the __toString method is called on, does not have any meaningful string 
> representation? Because if not, core implementation fully serves its purpose 
> throwing Fatal error now, even if it is non-standard way.

 

There are many reasons why you would want to throw an exception in 
__toString(), just like in any other method. 

Some of them may be recoverable, some may not be. Sorry I don’t have an example 
at hand.

 

But even if the error is “not recoverable”, you still want to leave your 
framework a chance to catch the uncaught exception to present a nice error page 
to the user, and handle the error appropriately (log, notify, etc.)

 

I’ve been thrilled to see that some move in the right direction has already 
been made in PHP 7 : for example, calling a method on a NULL value will throw 
an exception instead of resulting in a fatal error as before.

As I see it, fatal errors should be reserved to *really* unrecoverable stuff, 
like memory exhausted or max execution time exceeded; the rest is just 
annoyance.

 

Anyway it would be good to just reopen the bug for now to give it some 
attention, as Zend Engine 3 is being written!

 

Cheers,

Ben

 

Reply via email to