Annotation of embedaddon/php/ext/standard/tests/serialize/serialization_miscTypes_001.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test serialize() & unserialize() functions: many types
3: --SKIPIF--
4: <?php
5: if (PHP_INT_SIZE != 4) {
6: die("skip this test is for 32bit platform only");
7: }
8: ?>
9: --FILE--
10: <?php
11: /* Prototype : proto string serialize(mixed variable)
12: * Description: Returns a string representation of variable (which can later be unserialized)
13: * Source code: ext/standard/var.c
14: * Alias to functions:
15: */
16: /* Prototype : proto mixed unserialize(string variable_representation)
17: * Description: Takes a string representation of variable and recreates it
18: * Source code: ext/standard/var.c
19: * Alias to functions:
20: */
21:
22:
23: echo "--- Testing Various Types ---\n";
24:
25: /* unset variable */
26: $unset_var = 10;
27: unset($unset_var);
28: /* array declaration */
29: $arr_var = array(0, 1, -2, 3.333333, "a", array(), array(NULL));
30:
31: $Variation_arr = array(
32: /* Integers */
33: 2147483647,
34: -2147483647,
35: 2147483648,
36: -2147483648,
37:
38: 0xFF00123, // hex integers
39: -0xFF00123,
40: 0x7FFFFFFF,
41: -0x7FFFFFFF,
42: 0x80000000,
43: -0x80000000,
44:
45: 01234567, // octal integers
46: -01234567,
47:
48: /* arrays */
49: array(), // zero elements
50: array(1, 2, 3, 12345666, -2344),
51: array(0, 1, 2, 3.333, -4, -5.555, TRUE, FALSE, NULL, "", '', " ",
52: array(), array(1,2,array()), "string", new stdclass
53: ),
54: &$arr_var, // Reference to an array
55:
56: /* nulls */
57: NULL,
58: null,
59:
60: /* strings */
61: "",
62: '',
63: " ",
64: ' ',
65: "a",
66: "string",
67: 'string',
68: "hello\0",
69: 'hello\0',
70: "123",
71: '123',
72: '\t',
73: "\t",
74:
75: /* booleans */
76: TRUE,
77: true,
78: FALSE,
79: false,
80:
81: /* Mixed types */
82: @TRUE123,
83: "123string",
84: "string123",
85: "NULLstring",
86:
87: /* unset/undefined vars */
88: @$unset_var,
89: @$undefined_var,
90: );
91:
92: /* Loop through to test each element in the above array */
93: for( $i = 0; $i < count($Variation_arr); $i++ ) {
94:
95: echo "\n-- Iteration $i --\n";
96: echo "after serialization => ";
97: $serialize_data = serialize($Variation_arr[$i]);
98: var_dump( $serialize_data );
99:
100: echo "after unserialization => ";
101: $unserialize_data = unserialize($serialize_data);
102: var_dump( $unserialize_data );
103: }
104:
105: echo "\nDone";
106: ?>
107: --EXPECTF--
108: --- Testing Various Types ---
109:
110: -- Iteration 0 --
111: after serialization => string(13) "i:2147483647;"
112: after unserialization => int(2147483647)
113:
114: -- Iteration 1 --
115: after serialization => string(14) "i:-2147483647;"
116: after unserialization => int(-2147483647)
117:
118: -- Iteration 2 --
119: after serialization => string(13) "d:2147483648;"
120: after unserialization => float(2147483648)
121:
122: -- Iteration 3 --
123: after serialization => string(14) "d:-2147483648;"
124: after unserialization => float(-2147483648)
125:
126: -- Iteration 4 --
127: after serialization => string(12) "i:267387171;"
128: after unserialization => int(267387171)
129:
130: -- Iteration 5 --
131: after serialization => string(13) "i:-267387171;"
132: after unserialization => int(-267387171)
133:
134: -- Iteration 6 --
135: after serialization => string(13) "i:2147483647;"
136: after unserialization => int(2147483647)
137:
138: -- Iteration 7 --
139: after serialization => string(14) "i:-2147483647;"
140: after unserialization => int(-2147483647)
141:
142: -- Iteration 8 --
143: after serialization => string(13) "d:2147483648;"
144: after unserialization => float(2147483648)
145:
146: -- Iteration 9 --
147: after serialization => string(14) "d:-2147483648;"
148: after unserialization => float(-2147483648)
149:
150: -- Iteration 10 --
151: after serialization => string(9) "i:342391;"
152: after unserialization => int(342391)
153:
154: -- Iteration 11 --
155: after serialization => string(10) "i:-342391;"
156: after unserialization => int(-342391)
157:
158: -- Iteration 12 --
159: after serialization => string(6) "a:0:{}"
160: after unserialization => array(0) {
161: }
162:
163: -- Iteration 13 --
164: after serialization => string(57) "a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:12345666;i:4;i:-2344;}"
165: after unserialization => array(5) {
166: [0]=>
167: int(1)
168: [1]=>
169: int(2)
170: [2]=>
171: int(3)
172: [3]=>
173: int(12345666)
174: [4]=>
175: int(-2344)
176: }
177:
178: -- Iteration 14 --
179: after serialization => string(239) "a:16:{i:0;i:0;i:1;i:1;i:2;i:2;i:3;d:3.3330000000000002;i:4;i:-4;i:5;d:-5.5549999999999997;i:6;b:1;i:7;b:0;i:8;N;i:9;s:0:"";i:10;s:0:"";i:11;s:1:" ";i:12;a:0:{}i:13;a:3:{i:0;i:1;i:1;i:2;i:2;a:0:{}}i:14;s:6:"string";i:15;O:8:"stdClass":0:{}}"
180: after unserialization => array(16) {
181: [0]=>
182: int(0)
183: [1]=>
184: int(1)
185: [2]=>
186: int(2)
187: [3]=>
188: float(3.333)
189: [4]=>
190: int(-4)
191: [5]=>
192: float(-5.555)
193: [6]=>
194: bool(true)
195: [7]=>
196: bool(false)
197: [8]=>
198: NULL
199: [9]=>
200: string(0) ""
201: [10]=>
202: string(0) ""
203: [11]=>
204: string(1) " "
205: [12]=>
206: array(0) {
207: }
208: [13]=>
209: array(3) {
210: [0]=>
211: int(1)
212: [1]=>
213: int(2)
214: [2]=>
215: array(0) {
216: }
217: }
218: [14]=>
219: string(6) "string"
220: [15]=>
221: object(stdClass)#2 (0) {
222: }
223: }
224:
225: -- Iteration 15 --
226: after serialization => string(94) "a:7:{i:0;i:0;i:1;i:1;i:2;i:-2;i:3;d:3.3333330000000001;i:4;s:1:"a";i:5;a:0:{}i:6;a:1:{i:0;N;}}"
227: after unserialization => array(7) {
228: [0]=>
229: int(0)
230: [1]=>
231: int(1)
232: [2]=>
233: int(-2)
234: [3]=>
235: float(3.333333)
236: [4]=>
237: string(1) "a"
238: [5]=>
239: array(0) {
240: }
241: [6]=>
242: array(1) {
243: [0]=>
244: NULL
245: }
246: }
247:
248: -- Iteration 16 --
249: after serialization => string(2) "N;"
250: after unserialization => NULL
251:
252: -- Iteration 17 --
253: after serialization => string(2) "N;"
254: after unserialization => NULL
255:
256: -- Iteration 18 --
257: after serialization => string(7) "s:0:"";"
258: after unserialization => string(0) ""
259:
260: -- Iteration 19 --
261: after serialization => string(7) "s:0:"";"
262: after unserialization => string(0) ""
263:
264: -- Iteration 20 --
265: after serialization => string(8) "s:1:" ";"
266: after unserialization => string(1) " "
267:
268: -- Iteration 21 --
269: after serialization => string(8) "s:1:" ";"
270: after unserialization => string(1) " "
271:
272: -- Iteration 22 --
273: after serialization => string(8) "s:1:"a";"
274: after unserialization => string(1) "a"
275:
276: -- Iteration 23 --
277: after serialization => string(13) "s:6:"string";"
278: after unserialization => string(6) "string"
279:
280: -- Iteration 24 --
281: after serialization => string(13) "s:6:"string";"
282: after unserialization => string(6) "string"
283:
284: -- Iteration 25 --
285: after serialization => string(13) "s:6:"hello ";"
286: after unserialization => string(6) "hello "
287:
288: -- Iteration 26 --
289: after serialization => string(14) "s:7:"hello\0";"
290: after unserialization => string(7) "hello\0"
291:
292: -- Iteration 27 --
293: after serialization => string(10) "s:3:"123";"
294: after unserialization => string(3) "123"
295:
296: -- Iteration 28 --
297: after serialization => string(10) "s:3:"123";"
298: after unserialization => string(3) "123"
299:
300: -- Iteration 29 --
301: after serialization => string(9) "s:2:"\t";"
302: after unserialization => string(2) "\t"
303:
304: -- Iteration 30 --
305: after serialization => string(8) "s:1:" ";"
306: after unserialization => string(1) " "
307:
308: -- Iteration 31 --
309: after serialization => string(4) "b:1;"
310: after unserialization => bool(true)
311:
312: -- Iteration 32 --
313: after serialization => string(4) "b:1;"
314: after unserialization => bool(true)
315:
316: -- Iteration 33 --
317: after serialization => string(4) "b:0;"
318: after unserialization => bool(false)
319:
320: -- Iteration 34 --
321: after serialization => string(4) "b:0;"
322: after unserialization => bool(false)
323:
324: -- Iteration 35 --
325: after serialization => string(14) "s:7:"TRUE123";"
326: after unserialization => string(7) "TRUE123"
327:
328: -- Iteration 36 --
329: after serialization => string(16) "s:9:"123string";"
330: after unserialization => string(9) "123string"
331:
332: -- Iteration 37 --
333: after serialization => string(16) "s:9:"string123";"
334: after unserialization => string(9) "string123"
335:
336: -- Iteration 38 --
337: after serialization => string(18) "s:10:"NULLstring";"
338: after unserialization => string(10) "NULLstring"
339:
340: -- Iteration 39 --
341: after serialization => string(2) "N;"
342: after unserialization => NULL
343:
344: -- Iteration 40 --
345: after serialization => string(2) "N;"
346: after unserialization => NULL
347:
348: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>