1--TEST--
2__serialize() mechanism (003): Interoperability of different serialization mechanisms
3--FILE--
4<?php
5
6class Test implements Serializable {
7    public function __sleep() {
8        echo "__sleep() called\n";
9    }
10
11    public function __wakeup() {
12        echo "__wakeup() called\n";
13    }
14
15    public function __serialize() {
16        echo "__serialize() called\n";
17        return ["key" => "value"];
18    }
19
20    public function __unserialize(array $data) {
21        echo "__unserialize() called\n";
22        var_dump($data);
23    }
24
25    public function serialize() {
26        echo "serialize() called\n";
27        return "payload";
28    }
29
30    public function unserialize($payload) {
31        echo "unserialize() called\n";
32        var_dump($payload);
33    }
34}
35
36$test = new Test;
37var_dump($s = serialize($test));
38var_dump(unserialize($s));
39
40var_dump(unserialize('C:4:"Test":7:{payload}'));
41
42?>
43--EXPECT--
44__serialize() called
45string(37) "O:4:"Test":1:{s:3:"key";s:5:"value";}"
46__unserialize() called
47array(1) {
48  ["key"]=>
49  string(5) "value"
50}
51object(Test)#2 (0) {
52}
53unserialize() called
54string(7) "payload"
55object(Test)#2 (0) {
56}
57