note 76086 added to function.json-encode
| From: | florent at user-factory dot com | Date: | Fri, 29 Jun 2007 11:18:40 +0000 |
| Subject: | note 76086 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128083@lists.php.net to get a copy of this message | ||
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;
-> {}
----
Server IP: 217.160.72.57
Probable Submitter: 217.128.191.102
----
Manual Page -- http://www.php.net/manual/en/function.json-encode.php
Edit -- https://master.php.net/note/edit/76086
Del: integrated -- https://master.php.net/note/delete/76086/integrated
Del: useless -- https://master.php.net/note/delete/76086/useless
Del: bad code -- https://master.php.net/note/delete/76086/bad+code
Del: spam -- https://master.php.net/note/delete/76086/spam
Del: non-english -- https://master.php.net/note/delete/76086/non-english
Del: in docs -- https://master.php.net/note/delete/76086/in+docs
Del: other reasons-- https://master.php.net/note/delete/76086
Reject -- https://master.php.net/note/reject/76086
Search -- https://master.php.net/manage/user-notes.php