FAQ
This code throws *Fatal error*: Method test::__toString() must not throw
an exception

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

The same problem causes throwing exceptions in function __autoload.

I think this behavior is against the logic of exceptions. Excellent
feature of PHP 5.3 would be to resolve this errors.

David Grudl

Search Discussions

  • Scott MacVicar at Dec 26, 2008 at 2:17 am

    On 26 Dec 2008, at 01:46, David Grudl wrote:

    This code throws *Fatal error*: Method test::__toString() must not
    throw an exception

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

    The same problem causes throwing exceptions in function __autoload.

    I think this behavior is against the logic of exceptions. Excellent
    feature of PHP 5.3 would be to resolve this errors.
    This is down to the design of the engine, we perform casting to
    strings in a lot of different places and it couldn't be guaranteed
    that the engine would handle any exceptions correctly.

    I'm pretty sure there is something in the internals archives about
    this change.

    Scott
  • Alexey Zakhlestin at Dec 26, 2008 at 7:14 am

    On Fri, Dec 26, 2008 at 4:46 AM, David Grudl wrote:
    This code throws *Fatal error*: Method test::__toString() must not throw an
    exception

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

    The same problem causes throwing exceptions in function __autoload.

    I think this behavior is against the logic of exceptions. Excellent feature
    of PHP 5.3 would be to resolve this errors.
    regarging __autoload, everything is correct, actually, as throwing
    exception doesn't let engine to try other variants (which is
    counter-intuitive). it is perfectly fine to have several autoloaders
    enabled.

    regarding __toString(), I am not convinced that it is unresolvable.
    Someone with better understanding of engine should comment


    --
    Alexey Zakhlestin
    http://www.milkfarmsoft.com/
  • Stan Vassilev | FM at Dec 27, 2008 at 2:46 pm
    Hi,

    With __autoload you can throw an exception as long as you define the class
    requested.
    If you don't, the fatal error from the fact the class isn't there is
    triggered before the exception and you never see it.

    A clutch would be eval-ing an empty class with the same name right before
    you throw. I leave up to you how appropriate that is.

    Regards,
    Stan Vassilev

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedDec 26, '08 at 1:48a
activeDec 27, '08 at 2:46p
posts4
users4
websitephp.net

People

Translate

site design / logo © 2022 Grokbase