1--TEST--
2Test serialize() & unserialize() functions: arrays (circular references)
3--INI--
4serialize_precision=100
5--FILE--
6<?php
7echo "\n--- Testing Circular reference of an array ---\n";
8
9echo "-- Normal array --\n";
10$arr_circ = array(0, 1, -2, 3.333333, "a", array(), &$arr_circ);
11$serialize_data = serialize($arr_circ);
12var_dump( $serialize_data );
13$arr_circ = unserialize($serialize_data);
14var_dump( $arr_circ );
15
16echo "\n-- Associative array --\n";
17$arr_asso = array("a" => "test");
18$arr_asso[ "b" ] = &$arr_asso[ "a" ];
19var_dump($arr_asso);
20$serialize_data = serialize($arr_asso);
21var_dump($serialize_data);
22$arr_asso = unserialize($serialize_data);
23var_dump($arr_asso);
24
25echo "\nDone";
26?>
27--EXPECT--
28--- Testing Circular reference of an array ---
29-- Normal array --
30string(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;}}"
31array(7) {
32  [0]=>
33  int(0)
34  [1]=>
35  int(1)
36  [2]=>
37  int(-2)
38  [3]=>
39  float(3.333333000000000101437080957111902534961700439453125)
40  [4]=>
41  string(1) "a"
42  [5]=>
43  array(0) {
44  }
45  [6]=>
46  &array(7) {
47    [0]=>
48    int(0)
49    [1]=>
50    int(1)
51    [2]=>
52    int(-2)
53    [3]=>
54    float(3.333333000000000101437080957111902534961700439453125)
55    [4]=>
56    string(1) "a"
57    [5]=>
58    array(0) {
59    }
60    [6]=>
61    *RECURSION*
62  }
63}
64
65-- Associative array --
66array(2) {
67  ["a"]=>
68  &string(4) "test"
69  ["b"]=>
70  &string(4) "test"
71}
72string(37) "a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;}"
73array(2) {
74  ["a"]=>
75  &string(4) "test"
76  ["b"]=>
77  &string(4) "test"
78}
79
80Done
81