#49096 [Com]: json_encode has side effect
| From: | xiezhenye at gmail dot com | Date: | Wed, 29 Jul 2009 09:33:29 +0000 |
| Subject: | #49096 [Com]: json_encode has side effect | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-140421@lists.php.net to get a copy of this message | ||
ID: 49096
Comment by: xiezhenye at gmail dot com
Reported By: xiezhenye at gmail dot com
Status: Open
Bug Type: JSON related
Operating System: *
PHP Version: 5.2.10
New Comment:
addition:
it will apears when the properties are protected or private.
Previous Comments:
------------------------------------------------------------------------
[2009-07-29 09:28:00] xiezhenye at gmail dot com
Description:
------------
json_encode has side effect and may affect array propterty and cause
RECURSION.
Reproduce code:
---------------
class Test {
protected $data;
function __construct($data) {
$this->data = $data;
}
}
$t = new Test(array('a'=>1, 'b'=>2));
print_r($t);
json_encode($t);
print_r($t);
Expected result:
----------------
Test Object
(
[data:protected] => Array
(
[a] => 1
[b] => 2
)
)
Test Object
(
[data:protected] => Array
(
[a] => 1
[b] => 2
)
)
Actual result:
--------------
Test Object
(
[data:protected] => Array
(
[a] => 1
[b] => 2
)
)
Test Object
(
[data:protected] => Array
*RECURSION*
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49096&edit=1