Re: Add __toArray() method to objects that would be called on cast to array
| From: | Marco Pivetta | Date: | Thu, 16 Mar 2017 00:01:22 +0000 |
| Subject: | Re: Add __toArray() method to objects that would be called on cast to array | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-98559@lists.php.net to get a copy of this message | ||
What changes is the interface of the
(array) operator.
On 16 Mar 2017 12:53 a.m., "Andrey Andreev" <narf@devilix.net> wrote:
> Hi,
>
> On Thu, Mar 16, 2017 at 1:33 AM, Marco Pivetta <ocramius@gmail.com> wrote:
> > Correct: passing an object that implements __toArray() to
> > an API that
> > uses an (array) cast internally will break or misbehave,
> > if this
> feature
> > is added to the language.
> >
>
> I'm not particularly interested in the idea anyway, but if you change
> code and *then* something changes - that's not a BC break.
>
> Also, I have to agree with Fleshgrinder on that we don't need more
> magic methods and using an interface would be much cleaner.
>
> Cheers,
> Andrey.
>