note 96248 deleted from function.json-encode by crell
| From: | crell@php.net | Date: | Thu, 30 Jun 2022 19:43:25 +0000 |
| Subject: | note 96248 deleted from function.json-encode by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218791@lists.php.net to get a copy of this message | ||
Note Submitter: 5hunter5 at mail dot ru
----
If I want to encode object whith all it's private and protected properties, then I implements
that methods in my object:
<?php
public function encodeJSON()
{
foreach ($this as $key => $value)
{
$json->$key = $value;
}
return json_encode($json);
}
public function decodeJSON($json_str)
{
$json = json_decode($json_str, 1);
foreach ($json as $key => $value)
{
$this->$key = $value;
}
}
?>
Or you may extend your class from base class, wich is implements that methods.
Found that much more simple than regular expressions with PHP serialized objects...