Re: Exception::__toString() not called

From: Date: Wed, 17 Mar 2004 15:54:53 +0000
Subject: Re: Exception::__toString() not called
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-8561@lists.php.net to get a copy of this message
Marcus and rest, Zeev and I took a long look at the whole __toString() issue. There is a problem today that make_printabl_zval() is being called in many places, some of which can't cope with a user-land __toString() being called. In order to support this we will have to do a complete restructuring of the opcodes something we don't want to do pre-5.0.0. Due to this reason we currently have a safe automatic __toString() call in print/echo. This will work with any overloaded extension which implements get_method(). We will try and call __toString() and if we don't succeed we will call the standard zval printing function. All other places, such as concat and friends will not automatically call __toString(). Internal extensions such as SimpleXML which implement cast_object() are NOT affected by this change. We continue to honor their conversion requests as usual. I will commit the patches soon and will roll RC1RC2. Hopefully tomorrow I'll roll the final RC1. Andi At 09:49 AM 3/17/2004 +0100, Marcus Boerger wrote:
Hello Andi, the problem is that we have many classes that the handler table to behave mostly like a default php object. We'd need to manually set the cast handler for all of them. marcus Wednesday, March 17, 2004, 9:45:26 AM, you wrote: The Exception class should support cast_object(). I don't see why we need to add extra flags. Andi At 11:45 PM 3/16/2004 +0100, Marcus Boerger wrote:
Hello Timm, hello Andi, i htought i had a better solution to the __toString() problem. But then i found out why we made it so complex. The reason IIRC was to prevent __toString() being called everywhere automatically when it is a user function. Havin said this the solution is very easy. We expand the signature of cast_object to inform about exactly this - whether user space functions may be called or not. From _convert_to_string() we set that param to zero and from make_printable_zval we set it to 1 and inside the cast function we only need to verify the type of the function if necessary. Even better would be to add a flag that disallows usercode functions. Because with such a flag we do not have a problem if a conversion calls an internal method which then calls a userspace function which it shouldn't. Anid? Tuesday, March 16, 2004, 10:22:24 PM, you wrote:
Hi,
Both of the following examples used to output the Exception::__toString() output, which they don't anymore:
$ php-dev -r '$e= new Exception(); echo $e, "\n";' Object id #1
$ php-dev -r '$e= new Exception(); echo (string)$e, "\n";' Object id #1
Works fine for userland objects:
$ php-dev -r 'class Foo { function __toString() { return "foo"; }} echo new Foo(), "\n";' foo
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#8561) next »