Re: json_encode ignores protected/private class members

From: Date: Thu, 09 Oct 2008 13:13:43 +0000
Subject: Re: json_encode ignores protected/private class members
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-40887@lists.php.net to get a copy of this message
Ok, nice solution, but I still don't see why json_encode ignores protected/private class members. I mean, why we need this feature. Vesselin Kenashkov wrote:
Until this gets fixed instead of declaring the properties public you can use a encode method like this: <? class c1 { protected $p1 = 'aa'; public $p2 = 'bb'; public function enc()
    {
    //print $this->p1;
    return json_encode(get_object_vars($this));//this will encode the protected var
    }
} $o = new c1; print $o->enc(); ?> On Thu, Oct 9, 2008 at 3:54 PM, Jarismar Chaves da Silva <jarismar_silva@adplabs.com.br <mailto:jarismar_silva@adplabs.com.br>> wrote:
    Hi internals,
     Does anyone knows why json_encode ignores protected/public class
    members ?
     I've searching about it on documentation an mailing lists but
    found nothing but workarounds.
     Until now I'm forced to change my classes to use public members
    when I need to send a PHP object on e.g. AJAX responses. It would
    be nice if json_encode also send those attributes or at least have
    a parameter to whether send non-public attributes or not.
    Thanks in advance.
    Jaris.
    -- 
    *Jarismar Chaves da Silva, M.Sc.*
    *ADP**Labs** Brazil**
    *jarismar_silva@adplabs.com.br
    <mailto:jarismar_silva@adplabs.com.br>
    <mailto:jarismar_silva@adplabs.com.br
    <mailto:jarismar_silva@adplabs.com.br>>
    http://www.adp.com
-- *Jarismar Chaves da Silva, M.Sc.* *ADP**Labs** Brazil** *+55 51 3327 1491 – Direct +55 51 9947 3613 – Mobile jarismar_silva@adplabs.com.br <mailto:jarismar_silva@adplabs.com.br> http://www.adp.com This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

« previous php.internals (#40887) next »