Re: Proposal: ArraySerializable interface
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)