Bug #52108 [NEW]: PHP-Bug in Array Key

From: Date: Thu, 17 Jun 2010 08:19:27 +0000
Subject: Bug #52108 [NEW]: PHP-Bug in Array Key
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-151568@lists.php.net to get a copy of this message
From:             
Operating system: Ubuntu 9.04 (AMD64)
PHP version:      Irrelevant
Package:          JSON related
Bug Type:         Bug
Bug description:PHP-Bug in Array Key

Description:
------------
Hello,

I've found an error in the keys of an array. If I have a JSON-String and
decode it with json_decode and cast the returned value in an array then I
get NULL trying to access an array entry (eg array[1]). The return value
should however be a stdClass object.

Yours sincerely,
Arne Göbel

Test script:
---------------
$jstr = '{"1": {"anzahl": "", "preis": "",
"einheit": "", "beschreibung":
"", "mwst": ""}, "2": {"anzahl": "22",
"preis": "3", "einheit": "",
"beschreibung": "", "mwst": ""}, "3":
{"anzahl": "12", "preis": "22",
"einheit": "", "beschreibung": "", "mwst":
""}, "4": {"anzahl": "",
"preis": "", "einheit": "", "beschreibung":
"", "mwst": ""}}';

$array = (array) json_decode($jstr);

echo '<pre>';
var_dump($array[2], $array);

echo phpversion();


Expected result:
----------------
array(
"2" => stdClass object
public anzahl = "22"
public preis = "3"
public einheit = ""
public beschreibung = ""
public mwst = ""
)

Actual result:
--------------
NULL

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



Thread (3 messages)

« previous php.bugs (#151568) next »