2008/10/10 Jarismar Chaves da Silva <[EMAIL PROTECTED]>:
>
>
> 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.
> <?php
> class Person {
>   protected $name;
>
>   public function __construct($sName) {
>       $this->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**
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> http://www.adp.com
>
>

Let's just for example say that class X has the username and password
values for the login system.

You've made them private as only this class should access them.

How are you going to stop the json_encode() from seeing them and
passing them on.




-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to