Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40893 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58051 invoked from network); 9 Oct 2008 13:50:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Oct 2008 13:50:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=mls@pooteeweet.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=mls@pooteeweet.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain pooteeweet.org from 88.198.8.16 cause and error) X-PHP-List-Original-Sender: mls@pooteeweet.org X-Host-Fingerprint: 88.198.8.16 bigtime.backendmedia.com Linux 2.6 Received: from [88.198.8.16] ([88.198.8.16:59458] helo=bigtime.backendmedia.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/47-48736-91C0EE84 for ; Thu, 09 Oct 2008 09:50:18 -0400 Received: from localhost (unknown [127.0.0.1]) by bigtime.backendmedia.com (Postfix) with ESMTP id 6C97F414405C; Thu, 9 Oct 2008 13:51:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at backendmedia.com Received: from bigtime.backendmedia.com ([127.0.0.1]) by localhost (bigtime.backendmedia.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CPAr9lLiyEU1; Thu, 9 Oct 2008 15:51:13 +0200 (CEST) Received: from [192.168.80.161] (unknown [195.226.16.50]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: mls@pooteeweet.org) by bigtime.backendmedia.com (Postfix) with ESMTP id 00640414405A; Thu, 9 Oct 2008 15:51:12 +0200 (CEST) Cc: David Coallier , Stefan Walk , internals@lists.php.net Message-ID: To: Dave Ingram In-Reply-To: <48EE0AF9.8020602@dmi.me.uk> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Date: Thu, 9 Oct 2008 15:49:59 +0200 References: <48EDFEED.8080605@adplabs.com.br> <261daaa10810090607h1876200ex1efa43a40cfb24c2@mail.gmail.com> <48EE0387.3040802@adplabs.com.br> <200810091517.37703.et@php.net> <48EE0AF9.8020602@dmi.me.uk> X-Mailer: Apple Mail (2.929.2) Subject: Re: [PHP-DEV] json_encode ignores protected/private class members From: mls@pooteeweet.org (Lukas Kahwe Smith) On 09.10.2008, at 15:45, Dave Ingram wrote: >> But when using json_encode I believe the developer wants to transfer >> the complete object state, just like when using serialize. >> Serialize does see private/protected class members, while >> json_encode not. > If you want to serialize an object, then use the appropriate > function. I > think that json_encode() has the correct behaviour - encoding only the > publicly-visible structure of an object. They have fundamentally > different aims. If you want to expose data to an external source (e.g. > JavaScript) then surely it would make sense for it to be a public > class > member? Why would you not want your PHP code to be able to access it? Because JSON is a language agnostic serialization format. Again I agree that in the usual situation you only want public, but the other use case is also quite legit. Having to add such a "hack" into every class is not very useable, especially until we have traits. regards, Lukas Kahwe Smith mls@pooteeweet.org