summaryrefslogtreecommitdiff
path: root/Zend/tests/constant_arrays.phpt
blob: 46a0f9252e579d2465b71f5f7e07f3363f9aa4d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
--TEST--
Constant arrays
--INI--
zend.enable_gc=1
--FILE--
<?php

define('FOOBAR', [1, 2, 3, ['foo' => 'bar']]);
const FOO_BAR = [1, 2, 3, ['foo' => 'bar']];

$x = FOOBAR;
$x[0] = 7;
var_dump($x, FOOBAR);

$x = FOO_BAR;
$x[0] = 7;
var_dump($x, FOO_BAR);

// ensure references are removed
$x = 7;
$y = [&$x];
define('QUX', $y);
$y[0] = 3;
var_dump($x, $y, QUX);

// ensure objects not allowed in arrays
var_dump(define('ELEPHPANT', [new StdClass]));

// ensure recursion doesn't crash
$recursive = [];
$recursive[0] = &$recursive;
var_dump(define('RECURSION', $recursive));

--EXPECTF--
array(4) {
  [0]=>
  int(7)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  array(1) {
    ["foo"]=>
    string(3) "bar"
  }
}
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  array(1) {
    ["foo"]=>
    string(3) "bar"
  }
}
array(4) {
  [0]=>
  int(7)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  array(1) {
    ["foo"]=>
    string(3) "bar"
  }
}
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  array(1) {
    ["foo"]=>
    string(3) "bar"
  }
}
int(3)
array(1) {
  [0]=>
  &int(3)
}
array(1) {
  [0]=>
  int(7)
}

Warning: Constants may only evaluate to scalar values or arrays in %s on line %d
bool(false)

Warning: Constants cannot be recursive arrays in %s on line %d
bool(false)