#49096 [Opn->Fbk]: json_encode has side effect

From: Date: Wed, 29 Jul 2009 11:30:07 +0000
Subject: #49096 [Opn->Fbk]: json_encode has side effect
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-140423@lists.php.net to get a copy of this message
ID: 49096 Updated by: scottmac@php.net Reported By: xiezhenye at gmail dot com -Status: Open +Status: Feedback Bug Type: JSON related Operating System: * PHP Version: 5.2.10 New Comment: 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 ) ) Previous Comments: ------------------------------------------------------------------------ [2009-07-29 09:33:28] xiezhenye at gmail dot com addition: it will apears when the properties are protected or private. ------------------------------------------------------------------------ [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

« previous php.bugs (#140423) next »