xref: /PHP-7.0/Zend/tests/constant_arrays.phpt (revision 388624d3)
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// ensure objects not allowed in arrays
27var_dump(define('ELEPHPANT', [new StdClass]));
28
29// ensure recursion doesn't crash
30$recursive = [];
31$recursive[0] = &$recursive;
32var_dump(define('RECURSION', $recursive));
33
34--EXPECTF--
35array(4) {
36  [0]=>
37  int(7)
38  [1]=>
39  int(2)
40  [2]=>
41  int(3)
42  [3]=>
43  array(1) {
44    ["foo"]=>
45    string(3) "bar"
46  }
47}
48array(4) {
49  [0]=>
50  int(1)
51  [1]=>
52  int(2)
53  [2]=>
54  int(3)
55  [3]=>
56  array(1) {
57    ["foo"]=>
58    string(3) "bar"
59  }
60}
61array(4) {
62  [0]=>
63  int(7)
64  [1]=>
65  int(2)
66  [2]=>
67  int(3)
68  [3]=>
69  array(1) {
70    ["foo"]=>
71    string(3) "bar"
72  }
73}
74array(4) {
75  [0]=>
76  int(1)
77  [1]=>
78  int(2)
79  [2]=>
80  int(3)
81  [3]=>
82  array(1) {
83    ["foo"]=>
84    string(3) "bar"
85  }
86}
87int(3)
88array(1) {
89  [0]=>
90  &int(3)
91}
92array(1) {
93  [0]=>
94  int(7)
95}
96
97Warning: Constants may only evaluate to scalar values or arrays in %s on line %d
98bool(false)
99
100Warning: Constants cannot be recursive arrays in %s on line %d
101bool(false)
102