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