Re: Add __toArray() method to objects that would be called on cast to array
| From: | Benoît Burnichon | Date: | Wed, 15 Mar 2017 19:29:21 +0000 |
| Subject: | Re: Add __toArray() method to objects that would be called on cast to array | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98543@lists.php.net to get a copy of this message | ||
>
> > Same restrictions could be applied to this magic method:
> >
>
> http://us3.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
> >
> > By this, I mean, no exceptions should be thrown in this method and return
> > value MUST be an array.
>
> Exceptions cannot be thrown from inside __toString() because that's
> hard to implement; it's not a "feature" that anybody wanted.
>
That is why I said 'could be applied'. I don't currently know whether this
will be hard to implement. Maybe these restrictions are unneeded but I
prefer to be stricter than necessary as it generally make it easier to
implement. But thanks for the clarification.