note 76086 deleted from function.json-encode by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 17:29:24 +0000 |
| Subject: | note 76086 deleted from function.json-encode by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133166@lists.php.net to get a copy of this message | ||
Note Submitter: florent at user-factory dot com
----
I thought json_encode() was an easy way to obtain a JSON expression for my objects until I realized
that private / protected values would not be processed ...
class MyObject {
private $id;
private $name;
public function _construct ($id, $name) {
$this->id = $id;
$this->name = $name;
}
public function toJson()
{
return json_encode($this);
}
}
$o = new MyObject('001', 'foo');
$json = $o->toJson();
echo $json;
-> {}