From:             todd at amiestreet dot com
Operating system: linux x86 (32 bit)
PHP version:      5.3.0alpha2
PHP Bug Type:     JSON related
Bug description:  json_encode mutates its parameter and has some class-specific 
state

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 bug report at http://bugs.php.net/?id=46215&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=46215&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=46215&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=46215&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=46215&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=46215&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=46215&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=46215&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=46215&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=46215&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=46215&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=46215&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=46215&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=46215&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=46215&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=46215&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=46215&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=46215&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=46215&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=46215&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=46215&r=mysqlcfg

Reply via email to