php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mjs at beebo dot org
New email:
PHP Version: OS:

 

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

$memcached->setOption(Memcached::OPT_SERIALIZER, 
Memcached::SERIALIZER_JSON);

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);

print_r($a1);

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

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

print_r($a2);
 

Expected result:
----------------
Array
(
    [bar] => 3
)
Array
(
    [bar] => 3
)


Actual result:
--------------
Array
(
    [bar] => 3
)
stdClass Object
(
    [bar] => 3
)


Patches

Pull Requests

History

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


 [2009-12-01 19:37 UTC] andrei@php.net
Fixed for the next release, actually.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC