facebook / facebook/hhvm

serialize() fails to preserve object references between invocations of custom serializers

Open
#7,253 2 comments 0 reactions 0 assignees View on GitHub
php5 incompatibility php7 incompatibility probably easy
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

Unlike PHP 5.4+, HHVM's implementation of serialize() does not detect and preserve references to the same object between invocations of custom serializers. [PHP Request #36424](https://bugs.php.net/bug.php?id=36424) is probably related.
### HHVM Version

HipHop VM 3.15.0-dev (rel)
Compiler: heads/master-0-g17e1c0b1425733e5f34287b674f2456978c9008b
Repo schema: 7457716dbd7150059b4a315d3f986266d72e8ad8
### Standalone code, or other way to reproduce the problem

https://3v4l.org/t5YP8

```
o = $o;
}
function serialize() {
return serialize([$this->o]);
}
function unserialize($s) {
$this->o = unserialize($s)[0];
}
}
$o = new stdClass;
$r = unserialize(serialize([new A($o), new A($o)]));
var_dump($r[0]->o === $r[1]->o);
```
### Expected result

```
bool(true)
```
### Actual result

```
bool(false)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.