1--TEST--
2Test array_change_key_case() function : usage variations - Pass different data types as $case arg
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only");
5--FILE--
6<?php
7/* Prototype  : array array_change_key_case(array $input [, int $case])
8 * Description: Returns an array with all string keys lowercased [or uppercased]
9 * Source code: ext/standard/array.c
10 */
11
12/*
13 * Pass different data types as $case argument to array_change_key_case() to test behaviour
14 * Where possible, CASE_UPPER has been entered as a string value
15 */
16
17echo "*** Testing array_change_key_case() : usage variations ***\n";
18
19// Initialise function arguments not being substituted
20$array = array ('one' => 1, 'TWO' => 2, 'Three' => 3);
21
22//get an unset variable
23$unset_var = 10;
24unset ($unset_var);
25
26// heredoc string
27$heredoc = <<<EOT
28CASE_UPPER
29EOT;
30
31// get a resource variable
32$fp = fopen(__FILE__, "r");
33
34// unexpected values to be passed to $case argument
35$inputs = array(
36
37       // int data
38/*1*/  0,
39       1,
40       12345,
41       -2345,
42
43       // float data
44/*5*/  10.5,
45       -10.5,
46       12.3456789000e10,
47       12.3456789000E-10,
48       .5,
49
50       // null data
51/*10*/ NULL,
52       null,
53
54       // boolean data
55/*12*/ true,
56       false,
57       TRUE,
58       FALSE,
59
60       // empty data
61/*16*/ "",
62       '',
63       array(),
64
65       // string data
66/*19*/ "CASE_UPPER",
67       'CASE_UPPER',
68       $heredoc,
69
70       // undefined data
71/*22*/ @$undefined_var,
72
73       // unset data
74/*23*/ @$unset_var,
75);
76
77// loop through each element of $inputs to check the behavior of array_change_key_case()
78$iterator = 1;
79foreach($inputs as $input) {
80  echo "\n-- Iteration $iterator --\n";
81  var_dump( array_change_key_case($array, $input) );
82  $iterator++;
83};
84
85echo "Done";
86?>
87--EXPECTF--
88*** Testing array_change_key_case() : usage variations ***
89
90-- Iteration 1 --
91array(3) {
92  ["one"]=>
93  int(1)
94  ["two"]=>
95  int(2)
96  ["three"]=>
97  int(3)
98}
99
100-- Iteration 2 --
101array(3) {
102  ["ONE"]=>
103  int(1)
104  ["TWO"]=>
105  int(2)
106  ["THREE"]=>
107  int(3)
108}
109
110-- Iteration 3 --
111array(3) {
112  ["ONE"]=>
113  int(1)
114  ["TWO"]=>
115  int(2)
116  ["THREE"]=>
117  int(3)
118}
119
120-- Iteration 4 --
121array(3) {
122  ["ONE"]=>
123  int(1)
124  ["TWO"]=>
125  int(2)
126  ["THREE"]=>
127  int(3)
128}
129
130-- Iteration 5 --
131array(3) {
132  ["ONE"]=>
133  int(1)
134  ["TWO"]=>
135  int(2)
136  ["THREE"]=>
137  int(3)
138}
139
140-- Iteration 6 --
141array(3) {
142  ["ONE"]=>
143  int(1)
144  ["TWO"]=>
145  int(2)
146  ["THREE"]=>
147  int(3)
148}
149
150-- Iteration 7 --
151array(3) {
152  ["ONE"]=>
153  int(1)
154  ["TWO"]=>
155  int(2)
156  ["THREE"]=>
157  int(3)
158}
159
160-- Iteration 8 --
161array(3) {
162  ["one"]=>
163  int(1)
164  ["two"]=>
165  int(2)
166  ["three"]=>
167  int(3)
168}
169
170-- Iteration 9 --
171array(3) {
172  ["one"]=>
173  int(1)
174  ["two"]=>
175  int(2)
176  ["three"]=>
177  int(3)
178}
179
180-- Iteration 10 --
181array(3) {
182  ["one"]=>
183  int(1)
184  ["two"]=>
185  int(2)
186  ["three"]=>
187  int(3)
188}
189
190-- Iteration 11 --
191array(3) {
192  ["one"]=>
193  int(1)
194  ["two"]=>
195  int(2)
196  ["three"]=>
197  int(3)
198}
199
200-- Iteration 12 --
201array(3) {
202  ["ONE"]=>
203  int(1)
204  ["TWO"]=>
205  int(2)
206  ["THREE"]=>
207  int(3)
208}
209
210-- Iteration 13 --
211array(3) {
212  ["one"]=>
213  int(1)
214  ["two"]=>
215  int(2)
216  ["three"]=>
217  int(3)
218}
219
220-- Iteration 14 --
221array(3) {
222  ["ONE"]=>
223  int(1)
224  ["TWO"]=>
225  int(2)
226  ["THREE"]=>
227  int(3)
228}
229
230-- Iteration 15 --
231array(3) {
232  ["one"]=>
233  int(1)
234  ["two"]=>
235  int(2)
236  ["three"]=>
237  int(3)
238}
239
240-- Iteration 16 --
241
242Warning: array_change_key_case() expects parameter 2 to be int, string given in %s on line %d
243NULL
244
245-- Iteration 17 --
246
247Warning: array_change_key_case() expects parameter 2 to be int, string given in %s on line %d
248NULL
249
250-- Iteration 18 --
251
252Warning: array_change_key_case() expects parameter 2 to be int, array given in %s on line %d
253NULL
254
255-- Iteration 19 --
256
257Warning: array_change_key_case() expects parameter 2 to be int, string given in %s on line %d
258NULL
259
260-- Iteration 20 --
261
262Warning: array_change_key_case() expects parameter 2 to be int, string given in %s on line %d
263NULL
264
265-- Iteration 21 --
266
267Warning: array_change_key_case() expects parameter 2 to be int, string given in %s on line %d
268NULL
269
270-- Iteration 22 --
271array(3) {
272  ["one"]=>
273  int(1)
274  ["two"]=>
275  int(2)
276  ["three"]=>
277  int(3)
278}
279
280-- Iteration 23 --
281array(3) {
282  ["one"]=>
283  int(1)
284  ["two"]=>
285  int(2)
286  ["three"]=>
287  int(3)
288}
289Done
290