1--TEST--
2Test array_replace and array_replace_recursive
3--FILE--
4<?php
5
6$array1 = array(
7    0 => 'dontclobber',
8    '1' => 'unclobbered',
9    'test2' => 0.0,
10    'test3' => array(
11        'testarray2' => true,
12        1 => array(
13            'testsubarray1' => 'dontclobber2',
14            'testsubarray2' => 'dontclobber3',
15    ),
16    ),
17);
18
19$array2 = array(
20    1 => 'clobbered',
21    'test3' => array(
22        'testarray2' => false,
23    ),
24    'test4' => array(
25        'clobbered3' => array(0, 1, 2),
26    ),
27);
28
29$array3 = array(array(array(array())));
30
31$array4 = array();
32$array4[] = &$array4;
33
34echo " -- Testing array_replace() --\n";
35$data = array_replace($array1, $array2);
36
37var_dump($data);
38
39echo " -- Testing array_replace_recursive() --\n";
40$data = array_replace_recursive($array1, $array2);
41
42var_dump($data);
43
44echo " -- Testing array_replace_recursive() w/ endless recusrsion --\n";
45try {
46    $data = array_replace_recursive($array3, $array4);
47    var_dump($data);
48} catch (\Error $e) {
49    echo $e->getMessage() . "\n";
50}
51
52?>
53--EXPECT--
54 -- Testing array_replace() --
55array(5) {
56  [0]=>
57  string(11) "dontclobber"
58  [1]=>
59  string(9) "clobbered"
60  ["test2"]=>
61  float(0)
62  ["test3"]=>
63  array(1) {
64    ["testarray2"]=>
65    bool(false)
66  }
67  ["test4"]=>
68  array(1) {
69    ["clobbered3"]=>
70    array(3) {
71      [0]=>
72      int(0)
73      [1]=>
74      int(1)
75      [2]=>
76      int(2)
77    }
78  }
79}
80 -- Testing array_replace_recursive() --
81array(5) {
82  [0]=>
83  string(11) "dontclobber"
84  [1]=>
85  string(9) "clobbered"
86  ["test2"]=>
87  float(0)
88  ["test3"]=>
89  array(2) {
90    ["testarray2"]=>
91    bool(false)
92    [1]=>
93    array(2) {
94      ["testsubarray1"]=>
95      string(12) "dontclobber2"
96      ["testsubarray2"]=>
97      string(12) "dontclobber3"
98    }
99  }
100  ["test4"]=>
101  array(1) {
102    ["clobbered3"]=>
103    array(3) {
104      [0]=>
105      int(0)
106      [1]=>
107      int(1)
108      [2]=>
109      int(2)
110    }
111  }
112}
113 -- Testing array_replace_recursive() w/ endless recusrsion --
114Recursion detected
115