Re: Proposal: ArraySerializable interface

From: Date: Wed, 11 Dec 2013 01:38:10 +0000
Subject: Re: Proposal: ArraySerializable interface
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-70581@lists.php.net to get a copy of this message
On 11 December 2013 02:36, Marco Pivetta <ocramius@gmail.com> wrote:class ObjectToArrayConverter > { > /** > * @param mixed $value > * > * @raturn array > */ > public static function toArray($value) > { > if (! (is_object($value) || is_array($value))) { > return $value; > } > > if (is_object($value) && method_exists($value, '__toArray')) { > return $value->__toArray(); > } > > return array_map(__METHOD__, (array) $value); > } > } > > Note: I didn't consider the case of cyclic references. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/

« previous php.internals (#70581) next »