hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

ArrayObject serialization doesn't serialize properties on the object

Open jmarrama opened this issue 12 years ago • 4 comments

$b = new ArrayObject();
$b["foo"] = 42;
$b->bar = "baz";
var_dump(serialize($b));
$c = unserialize(serialize($b));
var_dump($c->bar);

Zend outputs:

string(80) "C:11:"ArrayObject":56:{x:i:0;a:1:{s:3:"foo";i:42;};m:a:1:{s:3:"bar";s:3:"baz";}}"
string(3) "baz"

HHVM outputs:

string(123) "C:11:"ArrayObject":99:{a:3:{s:7:"storage";a:1:{s:3:"foo";i:42;}s:5:"flags";i:0;s:13:"iteratorClass";s:13:"ArrayIterator";}}"

Notice: Undefined property: ArrayObject::$bar in /home/jmarrama/scratch/arr_obj_serialize/arrobj.php on line 15
NULL

Notice that the serialized representation lacks the "bar" property in HHVM.

jmarrama avatar Mar 21 '14 21:03 jmarrama

Maybe related - https://github.com/facebook/hhvm/issues/2162

SonicGD avatar Mar 26 '14 07:03 SonicGD

Thanks for reporting this. Feel free to submit a PR if you (or someone else reading this) gets to this before we do.

scannell avatar Apr 02 '14 17:04 scannell

Same problem with json_encode:

$arr = [];
$ao = new ArrayObject($arr, ArrayObject::STD_PROP_LIST);
$ao->var1 = 'var1';
echo json_encode($ao) . "\n";

But with ArrayObject::ARRAY_AS_PROPS seems it works OK.

Seems to me like a regresion because on HHVM 2.4 its work OK with STD_PROP_LIST too.

Kozzi11 avatar May 09 '14 07:05 Kozzi11

This works in master. The Problem with json_encode persists.

SiebelsTim avatar Jun 11 '14 08:06 SiebelsTim