ID:               46215
 Updated by:       [EMAIL PROTECTED]
 Reported By:      todd at amiestreet dot com
-Status:           Assigned
+Status:           Closed
 Bug Type:         JSON related
 Operating System: linux x86 (32 bit)
 PHP Version:      5.3.0alpha2
 Assigned To:      felipe
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2, 5.3 and HEAD.


Previous Comments:
------------------------------------------------------------------------

[2008-10-02 00:46:10] todd at amiestreet dot com

Description:
------------
The second time json_encode is called on objects of a given class, the
private variables of the first *instance* serialize as null.

Also, print_r produces different output after json_encode is called on
an object.

Reproduce code:
---------------
<?php
class Blah {
    protected $a = array();
}

$a = new Blah; $b = new Blah;
header('Content-type: text/plain');

print ($s1 = serialize($a)) . "\n";
print "--------------------------------------------------\n";

// Comment out either of the following lines and all is well

$print_a1 = print_r($a, true);
$junk = json_encode($a);
$print_a2 = print_r($a, true);
$junk = json_encode($b); // <-- unrelated variable!!!

print ($s2 = serialize($a)) . "\n\n";

print "\n\n" . $print_a1 . "\n" . $print_a2;
?>

Expected result:
----------------
serialize() called before and after the second json_encode should
return the exact same result, given they're called on the same
unmodified variable. ($s1 and $s2 should be equal but aren't)

$print_a and $print_b should also be equal, but calling json_encode
causes print_r to mistakenly detect recursion.

Actual result:
--------------
O:4:"Blah":1:{s:4:"�*�a";a:0:{}}
--------------------------------------------------
O:4:"Blah":1:{s:4:"�*�a";N;}



Blah Object
(
    [a:protected] => Array
        (
        )

)

Blah Object
(
    [a:protected] => Array
 *RECURSION*
)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=46215&edit=1

Reply via email to