Re: Inconsistent json_decode() results

From: Date: Wed, 05 May 2010 20:11:22 +0000
Subject: Re: Inconsistent json_decode() results
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-304922@lists.php.net to get a copy of this message
On 5 May 2010 20:02, Michael Shadle <mike503@gmail.com> wrote: > 2010/5/5 Michiel Sikma <michiel@thingmajig.org>: > > > By the way, if you're stuck on 5.2.10, you could simply cast the result > to > > array: > > > > var_dump((array)json_decode('{"_urls": ["a", > > "b"]}')); > > I don't see a "available starting in 5.x.x" notice, so I think it's > been there for a long time... > > http://www.php.net/json_decode > You're right, but this is about how 5.2.10 ignores the second parameter and always returns a class, which appears to be a bug. I'm not sure which other versions have this same problem, but 5.2.11 has correct behavior, which seems to suggest they found and fixed it by then. I can't find an entry for this problem in PHP's bug database, however. My suggestion to typecast the result of json_decode() should only be followed if you need an array and are required to work with version 5.2.10. Michiel

« previous php.general (#304922) next »