xref: /PHP-8.2/ext/standard/tests/serialize/001.phpt (revision 902d6439)
1--TEST--
2serialize()/unserialize()/var_dump()
3--INI--
4serialize_precision=100
5--FILE--
6<?php
7#[AllowDynamicProperties]
8class t
9{
10    function __construct()
11    {
12        $this->a = "hallo";
13    }
14}
15
16#[AllowDynamicProperties]
17class s
18{
19    public $a;
20    public $b;
21    public $c;
22
23    function __construct()
24    {
25        $this->a = "hallo";
26        $this->b = "php";
27        $this->c = "world";
28        $this->d = "!";
29    }
30
31    function __sleep()
32    {
33        echo "__sleep called\n";
34        return array("a","c");
35    }
36
37    function __wakeup()
38    {
39        echo "__wakeup called\n";
40    }
41}
42
43
44echo serialize(NULL)."\n";
45echo serialize((bool) true)."\n";
46echo serialize((bool) false)."\n";
47echo serialize(1)."\n";
48echo serialize(0)."\n";
49echo serialize(-1)."\n";
50echo serialize(2147483647)."\n";
51echo serialize(-2147483647)."\n";
52echo serialize(1.123456789)."\n";
53echo serialize(1.0)."\n";
54echo serialize(0.0)."\n";
55echo serialize(-1.0)."\n";
56echo serialize(-1.123456789)."\n";
57echo serialize("hallo")."\n";
58echo serialize(array(1,1.1,"hallo",NULL,true,array()))."\n";
59
60$t = new t();
61$data = serialize($t);
62echo "$data\n";
63$t = unserialize($data);
64var_dump($t);
65
66$t = new s();
67$data = serialize($t);
68echo "$data\n";
69$t = unserialize($data);
70var_dump($t);
71
72$a = array("a" => "test");
73$a[ "b" ] = &$a[ "a" ];
74var_dump($a);
75$data = serialize($a);
76echo "$data\n";
77$a = unserialize($data);
78var_dump($a);
79?>
80--EXPECTF--
81N;
82b:1;
83b:0;
84i:1;
85i:0;
86i:-1;
87i:2147483647;
88i:-2147483647;
89d:1.123456789000000011213842299184761941432952880859375;
90d:1;
91d:0;
92d:-1;
93d:-1.123456789000000011213842299184761941432952880859375;
94s:5:"hallo";
95a:6:{i:0;i:1;i:1;d:1.100000000000000088817841970012523233890533447265625;i:2;s:5:"hallo";i:3;N;i:4;b:1;i:5;a:0:{}}
96O:1:"t":1:{s:1:"a";s:5:"hallo";}
97object(t)#%d (1) {
98  ["a"]=>
99  string(5) "hallo"
100}
101__sleep called
102O:1:"s":2:{s:1:"a";s:5:"hallo";s:1:"c";s:5:"world";}
103__wakeup called
104object(s)#%d (3) {
105  ["a"]=>
106  string(5) "hallo"
107  ["b"]=>
108  NULL
109  ["c"]=>
110  string(5) "world"
111}
112array(2) {
113  ["a"]=>
114  &string(4) "test"
115  ["b"]=>
116  &string(4) "test"
117}
118a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;}
119array(2) {
120  ["a"]=>
121  &string(4) "test"
122  ["b"]=>
123  &string(4) "test"
124}
125