> -----Original Message-----
> From: Pierre Joye [mailto:[email protected]]
> Sent: 12 May 2010 11:33
> To: Stanislav Malyshev
> Cc: Sara Golemon; PHP Internals
> Subject: Re: [PHP-DEV] Re: [PHP-CVS] svn: /php/php-src/trunk/
> NEWS ext/json/json.c ext/json/php_json.h
ext/json/tests/serialize.phpt
>
> hi!
>
> On Wed, May 12, 2010 at 4:25 AM, Stanislav Malyshev
> <[email protected]> wrote:
> > Hi!
> >
> >> Add JSON_Serializable interface
> >> Objects implementing JSON_Serializable will have their
> >> ->jsonSerialize() method called
> >>
> >> Similar to serialize() and __sleep()
> >
> > Why should we have special mechanism for JSON? I.e., now we
> have one
> > for serialize(), separate one for json, then we'd have separate
one
> > for storing object as XML or YAML, etc. etc. IMHO it's not
> a very good
> > design - having separate method for every format of data
> storage. Why
> > can't we just use whatever serialize() would see and wrap
> it in JSON after that?
>
> Serialize is a different thing but Json seems to be standard
> enough to justify a __toJson method. In any case, using _ in
> classes name is a no go, as we decided a while back. We can
> call JsonSerializable if we keep the interface instead of
> moving this feature to __toJson (which I prefer).
>
> Cheers,
> --
> Pierre
>
Hi,
Keep thinking with what is in php.next that interfaces seem
overkill?
Doesn't
trait JSON
{
function toJSONString()
{
return json_encode(get_object_vars($this));
}
}
class A
{
use JSON;
public $a = 1;
protected $b = 2;
private $c = 3;
}
$a = new A();
echo $a->toJSONString(), "\n";
Make better sense?
Don't have to implement any interfaces, yet I still have freedom to
override it either in a differing trait or in the class.
Jared
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php