Re: __toString()
| From: | Jon Parise | Date: | Mon, 15 Dec 2003 06:37:39 +0000 |
| Subject: | Re: __toString() | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-6459@lists.php.net to get a copy of this message | ||
On Mon, Dec 15, 2003 at 01:32:57AM -0500, George Schlossnagle wrote:
> >Nope. How is it different or nicer than doing
> >$defect->thrownException()->__toString()?
> >It saves you 4 characters?
>
> 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 {
> 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.
I think that's reasonable, although I think it's generally useful for
all objects to implicitly implement 'Stringable' (in the same way that
they all implement "Cloneable", via the __clone() method, today).
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)