Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40914 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65310 invoked from network); 10 Oct 2008 12:52:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2008 12:52:23 -0000 Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 216.239.58.189 as permitted sender) X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 216.239.58.189 gv-out-0910.google.com Received: from [216.239.58.189] ([216.239.58.189:41847] helo=gv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/05-38373-5005FE84 for ; Fri, 10 Oct 2008 08:52:22 -0400 Received: by gv-out-0910.google.com with SMTP id e6so153667gvc.37 for ; Fri, 10 Oct 2008 05:52:19 -0700 (PDT) Received: by 10.103.22.11 with SMTP id z11mr862815mui.83.1223631008507; Fri, 10 Oct 2008 02:30:08 -0700 (PDT) Received: by 10.103.212.17 with HTTP; Fri, 10 Oct 2008 02:30:08 -0700 (PDT) Message-ID: <10845a340810100230s24bc2617ge4a0cf5a913d01c3@mail.gmail.com> Date: Fri, 10 Oct 2008 10:30:08 +0100 Reply-To: RQuadling@GoogleMail.com To: internals@lists.php.net In-Reply-To: <4D.EB.48736.5C97EE84@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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> Subject: Re: [PHP-DEV] json_encode ignores protected/private class members From: rquadling@googlemail.com ("Richard Quadling") 2008/10/9 Rodrigo Saboya : > 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. > > -- Rodrigo Saboya > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > A simply userland solution would be to use an abstract base class with json_encode()/json_decode() as public final methods. All classes needing to support json_encode/json_decode would simply need to extend from this base class. No need to add even more "magic" to the base stdClass. Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"