Re: Proposal: ArraySerializable interface

From: Date: Wed, 11 Dec 2013 08:18:05 +0000
Subject: Re: Proposal: ArraySerializable interface
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-70585@lists.php.net to get a copy of this message
On 11 December 2013 01:23, chobie <chobieee@gmail.com> wrote:

> Hi,
>
> I've got an idea for adding common way to convert array from object:
> ArraySerializable interface and to allow the changing of existing
> array conversion mechanism.


...

Currently, the implicit object to array conversion does not work
> recursively. This propose changes object to array conversion behaviour
> which implements ArraySerializable interface. specifically
> ArraySerializable::__toArray method overrides current (array) cast.
>
>     interface ArraySerializable
>     {
>         /** @return array */
>         public function __toArray();
>     }
>

I have no problems with the proposal in general, however did you see there
is an RFC already related to this (
https://wiki.php.net/rfc/object_cast_to_types)
that has a patch you might
like to reference?

I would still like to see the full suite of type-conversion magic methods,
I don't see an argument for implementing one and not the others.

Not sure if this should come with an interface, for example __toString()
does not come with a StringSerializable interface.

Perhaps __toArray() / __toString / __toWhatever should all be available
without an interface, but also have interfaces that wrap them for the sake
of typehinting (which means adding an interface for __toString)


Thread (10 messages)

« previous php.internals (#70585) next »