Re: __toString()
| From: | George Schlossnagle | Date: | Mon, 15 Dec 2003 06:32:57 +0000 |
| Subject: | Re: __toString() | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-6457@lists.php.net to get a copy of this message | ||
On Dec 15, 2003, at 1:09 AM, Andi Gutmans wrote:
At 08:35 PM 12/14/2003 -0500, Jon Parise wrote:If it doesn't do anything 'magical', why bother with the __? If you always have to call it manually, it should be an interface: interface Stringable {On Sun, Dec 14, 2003 at 03:41:10PM +0100, Sebastian Bergmann wrote: It is supported by "print" and for internal extensions such as SimpleXML which require this.How is it supported by "print" whenprint $defect->thrownException()does not work but the object returned from thrownException() has a __toString() method?Hopefully, this still works (don't have a recent PHP5 build to try):Nope. How is it different or nicer than doing $defect->thrownException()->__toString()? It saves you 4 characters?print (string)$defect->thrownException();The explicit cast also addresses this case:print (string)$defect->thrownException() . "\n";
public function toString();} And that way extensions and user code both can decide if they want to give special treatment to objects that implement Stringable. George