1--TEST--
2Test serialize() & unserialize() functions: arrays (circular references)
3--INI--
4serialize_precision=100
5--FILE--
6<?php
7/* Prototype  : proto string serialize(mixed variable)
8 * Description: Returns a string representation of variable (which can later be unserialized)
9 * Source code: ext/standard/var.c
10 * Alias to functions:
11 */
12/* Prototype  : proto mixed unserialize(string variable_representation)
13 * Description: Takes a string representation of variable and recreates it
14 * Source code: ext/standard/var.c
15 * Alias to functions:
16 */
17
18echo "\n--- Testing Circular reference of an array ---\n";
19
20echo "-- Normal array --\n";
21$arr_circ = array(0, 1, -2, 3.333333, "a", array(), &$arr_circ);
22$serialize_data = serialize($arr_circ);
23var_dump( $serialize_data );
24$arr_circ = unserialize($serialize_data);
25var_dump( $arr_circ );
26
27echo "\n-- Associative array --\n";
28$arr_asso = array("a" => "test");
29$arr_asso[ "b" ] = &$arr_asso[ "a" ];
30var_dump($arr_asso);
31$serialize_data = serialize($arr_asso);
32var_dump($serialize_data);
33$arr_asso = unserialize($serialize_data);
34var_dump($arr_asso);
35
36echo "\nDone";
37?>
38--EXPECTF--
39--- Testing Circular reference of an array ---
40-- Normal array --
41string(238) "a:7:{i:0;i:0;i:1;i:1;i:2;i:-2;i:3;d:3.333333000000000101437080957111902534961700439453125;i:4;s:1:"a";i:5;a:0:{}i:6;a:7:{i:0;i:0;i:1;i:1;i:2;i:-2;i:3;d:3.333333000000000101437080957111902534961700439453125;i:4;s:1:"a";i:5;a:0:{}i:6;R:8;}}"
42array(7) {
43  [0]=>
44  int(0)
45  [1]=>
46  int(1)
47  [2]=>
48  int(-2)
49  [3]=>
50  float(3.333333)
51  [4]=>
52  string(1) "a"
53  [5]=>
54  array(0) {
55  }
56  [6]=>
57  &array(7) {
58    [0]=>
59    int(0)
60    [1]=>
61    int(1)
62    [2]=>
63    int(-2)
64    [3]=>
65    float(3.333333)
66    [4]=>
67    string(1) "a"
68    [5]=>
69    array(0) {
70    }
71    [6]=>
72    *RECURSION*
73  }
74}
75
76-- Associative array --
77array(2) {
78  ["a"]=>
79  &string(4) "test"
80  ["b"]=>
81  &string(4) "test"
82}
83string(37) "a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;}"
84array(2) {
85  ["a"]=>
86  &string(4) "test"
87  ["b"]=>
88  &string(4) "test"
89}
90
91Done
92