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
| From: | Johannes Schlüter | Date: | Thu, 13 May 2010 19:46:58 +0000 |
| 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 | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48283@lists.php.net to get a copy of this message | ||
On Thu, 2010-05-13 at 20:27 +0100, Jared Williams wrote:
> 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;
> }
No. The goal is to allow json_encode($foo); to do what makes sense in
the case. You might re-use the implementation by implementing it using
traits, but tha's a different problem than what this interface solves.
johannes