Re: Proposal: ArraySerializable interface

From: Date: Thu, 12 Dec 2013 23:19:55 +0000
Subject: Re: Proposal: ArraySerializable interface
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-70613@lists.php.net to get a copy of this message
On 11 December 2013 16:29, chobie <chobieee@gmail.com> wrote: > 2013/12/11 Marco Pivetta <ocramius@gmail.com>: > > > > I'm actually wondering about the opposite case. > > What would I have to do to have the previous behavior working on an > ArraySerializable instance (basically ignore > __toArray() for one > particular cast)? > > I don't want to go the reflection way :-) > > I'm curious about your story. What king of work do you do? > There are quite a lot of cases where array cast behavior is currently something we rely on (to avoid reflection). Here's two that come into my mind: - Using __sleep() and returning array keys for parent classes' properties: public function __sleep() { return array_keys((array) $this); // handles the "\0*\0" or "\0ClassName\0" properties } - Relying on (array) casting returning all property names all the time - Some stuff I've been working about converting objects to arrays to objects (GeneratedHydrator) Those are some of the bc breaks that I have on top of my mind. I'd rather prefer having userland implementations as I mentioned before (since it's possible). Casting to (array) actually solves more complex problems, while solving the problem of extracting data is fairly simple Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

« previous php.internals (#70613) next »