hhvm
hhvm copied to clipboard
ArrayObject serialization doesn't serialize properties on the object
$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.
Maybe related - https://github.com/facebook/hhvm/issues/2162
Thanks for reporting this. Feel free to submit a PR if you (or someone else reading this) gets to this before we do.
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.
This works in master. The Problem with json_encode persists.