From:             markus dot kristo at esportnetwork dot com
Operating system: Windows XP, Linux
PHP version:      5.2.7
PHP Bug Type:     Arrays related
Bug description:  jsondecode 

Description:
------------
json_encoding and json_decoding an array with string indices as numbers
starting from anything else than zero will create an array that can't be
used to fetch elements from. 

Note that this only happens when you cast the resulting object from
json_decode to an array. 

Please look at the attached code example for more information about this
bug.

Reproduce code:
---------------
<?php

$array = array("1" => "one"); // array("0" => "zero") works fine.

$foo = (array) json_decode(json_encode($array)); 
// $foo = json_decode(json_encode($array), true) works fine

var_dump($foo);
// array(1) {
//  ["1"]=>
//  string(3) "one"
// }

var_dump($foo["1"]); // Outputs PHP Notice and NULL expected "one"

?>

Expected result:
----------------
I expect the last var_dump to output "one"

Actual result:
--------------
The last var_dump outputs NULL and a PHP Notice "undefined index: 1" is
shown

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

Reply via email to