623d73159c7353f9fe2d92d7e8ca5528d598b567
[awesomized/ext-ion] / tests / serialize / serializable.phpt
1 --TEST--
2 ion\serialize/serializable
3 --EXTENSIONS--
4 ion
5 --FILE--
6 TEST
7 <?php
8 class test implements Serializable {
9 protected $data;
10 function serialize() : string {
11 return "foobar";
12 }
13 function unserialize(string $data) : void {
14 $this->data = $data;
15 }
16 }
17 $t = new test;
18 $s = ion\serialize($t);
19 echo $s, "\n";
20 $c = ion\unserialize($s);
21 var_dump($c);
22
23 class recursive implements Serializable {
24 private $id;
25 function __construct(
26 protected $r
27 ) {
28 }
29 function serialize() : string {
30 if ($this->r) {
31 return "node:" . ion\serialize($this->r);
32 } else {
33 return "leaf";
34 }
35 }
36 function unserialize(string $data) : void {
37 if ($data === "leaf") {
38 $this->id = $data;
39 } else {
40 $this->id = substr($data, 0, 4);
41 $this->r = ion\unserialize(substr($data, 5));
42 }
43 }
44 }
45 $tree = new recursive(new recursive(null));
46 var_dump($tree);
47 $s = ion\serialize($tree);
48 echo $s,"\n";
49 var_dump(ion\unserialize($s));
50 ?>
51 DONE
52 --EXPECTF--
53 TEST
54
55 Deprecated: test implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %sserialize/serializable.php on line %d
56 PHP::S::test::"foobar"
57 object(test)#5 (1) {
58 ["data":protected]=>
59 string(6) "foobar"
60 }
61
62 Deprecated: recursive implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %sserialize/serializable.php on line %d
63 object(recursive)#%d (2) {
64 ["id":"recursive":private]=>
65 NULL
66 ["r":protected]=>
67 object(recursive)#%d (2) {
68 ["id":"recursive":private]=>
69 NULL
70 ["r":protected]=>
71 NULL
72 }
73 }
74 PHP::S::recursive::"node:S::recursive::\"leaf\""
75 object(recursive)#%d (2) {
76 ["id":"recursive":private]=>
77 string(4) "node"
78 ["r":protected]=>
79 object(recursive)#%d (2) {
80 ["id":"recursive":private]=>
81 string(4) "leaf"
82 ["r":protected]=>
83 NULL
84 }
85 }
86 DONE