|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #58773 JSON serializer returns objects if arrays added
Submitted: 2009-07-24 06:37 UTC Modified: 2009-12-01 19:37 UTC
From: mjs at beebo dot org Assigned:
Status: Closed Package: memcached (PECL)
PHP Version: Irrelevant OS: OS X
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
44 + 41 = ?
Subscribe to this entry?

 [2009-07-24 06:37 UTC] mjs at beebo dot org
The JSON serializer, as configured with


returns objects upon deserialization (i.e. $memcached-
>get(...)) even if an array was added in the first place.

It seems as though internally, json_decode($s) is being used 
instead of json_decode($s, true).

(Perhaps there needs to be an Memcached::SERIALIZER_JSON and 
Memcached::SERIALIZER_JSON_OBJECT serialization styles.)

Reproduce code:
$memcached = new Memcached();

$memcached->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_JSON);
$memcached->addServers(array(array("localhost", 11211)));
$a1 = array("bar" => 3);


$memcached->set("foo", $a1);

$a2 = $memcached->get("foo");


Expected result:
    [bar] => 3
    [bar] => 3

Actual result:
    [bar] => 3
stdClass Object
    [bar] => 3


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-01 19:36 UTC]
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at

 [2009-12-01 19:37 UTC]
Fixed for the next release, actually.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 23 16:01:24 2020 UTC