Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40909 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54212 invoked from network); 10 Oct 2008 12:22:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2008 12:22:30 -0000 Authentication-Results: pb1.pair.com header.from=jarismar_silva@adplabs.com.br; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jarismar_silva@adplabs.com.br; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adplabs.com.br designates 201.84.224.135 as permitted sender) X-PHP-List-Original-Sender: jarismar_silva@adplabs.com.br X-Host-Fingerprint: 201.84.224.135 mx.adplabs.com.br Linux 2.6 Received: from [201.84.224.135] ([201.84.224.135:38707] helo=mx.adplabs.com.br) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CA/B2-38373-2094FE84 for ; Fri, 10 Oct 2008 08:22:28 -0400 Received: from kafe.adplabs.com.br (mail.adplabs.com.br [201.84.224.133]) by mx.adplabs.com.br (Postfix) with ESMTP id 6CA1C4E4189; Fri, 10 Oct 2008 08:51:36 -0300 (BRT) Received: from [10.159.1.169] (jarismar.adplabs.com.br [10.159.1.169]) by kafe.adplabs.com.br (Postfix) with ESMTP id F301340902D; Fri, 10 Oct 2008 08:51:30 -0300 (BRT) Message-ID: <48EF41F7.3020400@adplabs.com.br> Date: Fri, 10 Oct 2008 08:52:23 -0300 User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Rodrigo Saboya CC: internals@lists.php.net References: <48EDFEED.8080605@adplabs.com.br> <261daaa10810090607h1876200ex1efa43a40cfb24c2@mail.gmail.com> <48EE0387.3040802@adplabs.com.br> <200810091517.37703.et@php.net> <48EE0A34.8020903@adplabs.com.br> <4D.EB.48736.5C97EE84@pb1.pair.com> In-Reply-To: <4D.EB.48736.5C97EE84@pb1.pair.com> Content-Type: multipart/alternative; boundary="------------010606090405060502020304" X-ADPLabs-MailScanner-Information: Please contact your ISP for more information X-ADPLabs-MailScanner: Found to be clean X-ADPLabs-MailScanner-From: jarismar_silva@adplabs.com.br X-Spam-Status: No Subject: Re: [PHP-DEV] json_encode ignores protected/private class members From: jarismar_silva@adplabs.com.br (Jarismar Chaves da Silva) --------------010606090405060502020304 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Rodrigo Saboya wrote: > Jarismar Chaves da Silva wrote: >> I agree with you. >> 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. >> Javascript does not have class-accessors so why not convert >> protected/private to public javascript attributes. > > In theory only the public members are relevant to anyone except the > object itself. If you need information about private/protected members > you are either using the wrong visibility for your variables or using > json for something it's not supposed to do. Yes, of course. But currently json_encode ignores the attributes even if the call is from inside the class. name = $sName; } public function toJSON() { return json_encode($this); } } $person = new Person('jaris'); print $person->toJSON(); // ==> will print an empty object e.g. {} ?> I don't know if I'm using json_encode for something it's not supposed to do. I'm using it to serialize an object to send it to another runtime-environment in response to an remote call, just like what I can do with SOAP, REST or RMI. In this context I don't see much sense in preventing protected/private data from being transfered. Regards, Jaris. > -- Rodrigo Saboya > -- *Jarismar Chaves da Silva, M.Sc.* *ADP**Labs** Brazil** *jarismar_silva@adplabs.com.br http://www.adp.com --------------010606090405060502020304--