xref: /PHP-8.2/Zend/tests/constant_arrays.phpt (revision 53aed48e)
1--TEST--
2Constant arrays
3--INI--
4zend.enable_gc=1
5--FILE--
6<?php
7
8define('FOOBAR', [1, 2, 3, ['foo' => 'bar']]);
9const FOO_BAR = [1, 2, 3, ['foo' => 'bar']];
10
11$x = FOOBAR;
12$x[0] = 7;
13var_dump($x, FOOBAR);
14
15$x = FOO_BAR;
16$x[0] = 7;
17var_dump($x, FOO_BAR);
18
19// ensure references are removed
20$x = 7;
21$y = [&$x];
22define('QUX', $y);
23$y[0] = 3;
24var_dump($x, $y, QUX);
25
26// objects are allowed in arrays
27define('ELEPHPANT', [new StdClass]);
28var_dump(ELEPHPANT);
29
30// ensure recursion doesn't crash
31$recursive = [];
32$recursive[0] = &$recursive;
33
34try {
35    define('RECURSION', $recursive);
36} catch (ValueError $exception) {
37    echo $exception->getMessage() . "\n";
38}
39?>
40--EXPECT--
41array(4) {
42  [0]=>
43  int(7)
44  [1]=>
45  int(2)
46  [2]=>
47  int(3)
48  [3]=>
49  array(1) {
50    ["foo"]=>
51    string(3) "bar"
52  }
53}
54array(4) {
55  [0]=>
56  int(1)
57  [1]=>
58  int(2)
59  [2]=>
60  int(3)
61  [3]=>
62  array(1) {
63    ["foo"]=>
64    string(3) "bar"
65  }
66}
67array(4) {
68  [0]=>
69  int(7)
70  [1]=>
71  int(2)
72  [2]=>
73  int(3)
74  [3]=>
75  array(1) {
76    ["foo"]=>
77    string(3) "bar"
78  }
79}
80array(4) {
81  [0]=>
82  int(1)
83  [1]=>
84  int(2)
85  [2]=>
86  int(3)
87  [3]=>
88  array(1) {
89    ["foo"]=>
90    string(3) "bar"
91  }
92}
93int(3)
94array(1) {
95  [0]=>
96  &int(3)
97}
98array(1) {
99  [0]=>
100  int(7)
101}
102array(1) {
103  [0]=>
104  object(stdClass)#1 (0) {
105  }
106}
107define(): Argument #2 ($value) cannot be a recursive array
108