|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-29 09:28 UTC] 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*
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 04:00:01 2025 UTC |
Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. Output from what you've given is: Test Object ( [data:protected] => Array ( [a] => 1 [b] => 2 ) ) Test Object ( [data:protected] => Array ( [a] => 1 [b] => 2 ) )