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: Retuns 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
88--EXPECTF--
89*** Testing array_change_key_case() : usage variations ***
90
91-- Iteration 1 --
92array(3) {
93  ["one"]=>
94  int(1)
95  ["two"]=>
96  int(2)
97  ["three"]=>
98  int(3)
99}
100
101-- Iteration 2 --
102array(3) {
103  ["ONE"]=>
104  int(1)
105  ["TWO"]=>
106  int(2)
107  ["THREE"]=>
108  int(3)
109}
110
111-- Iteration 3 --
112array(3) {
113  ["ONE"]=>
114  int(1)
115  ["TWO"]=>
116  int(2)
117  ["THREE"]=>
118  int(3)
119}
120
121-- Iteration 4 --
122array(3) {
123  ["ONE"]=>
124  int(1)
125  ["TWO"]=>
126  int(2)
127  ["THREE"]=>
128  int(3)
129}
130
131-- Iteration 5 --
132array(3) {
133  ["ONE"]=>
134  int(1)
135  ["TWO"]=>
136  int(2)
137  ["THREE"]=>
138  int(3)
139}
140
141-- Iteration 6 --
142array(3) {
143  ["ONE"]=>
144  int(1)
145  ["TWO"]=>
146  int(2)
147  ["THREE"]=>
148  int(3)
149}
150
151-- Iteration 7 --
152array(3) {
153  ["ONE"]=>
154  int(1)
155  ["TWO"]=>
156  int(2)
157  ["THREE"]=>
158  int(3)
159}
160
161-- Iteration 8 --
162array(3) {
163  ["one"]=>
164  int(1)
165  ["two"]=>
166  int(2)
167  ["three"]=>
168  int(3)
169}
170
171-- Iteration 9 --
172array(3) {
173  ["one"]=>
174  int(1)
175  ["two"]=>
176  int(2)
177  ["three"]=>
178  int(3)
179}
180
181-- Iteration 10 --
182array(3) {
183  ["one"]=>
184  int(1)
185  ["two"]=>
186  int(2)
187  ["three"]=>
188  int(3)
189}
190
191-- Iteration 11 --
192array(3) {
193  ["one"]=>
194  int(1)
195  ["two"]=>
196  int(2)
197  ["three"]=>
198  int(3)
199}
200
201-- Iteration 12 --
202array(3) {
203  ["ONE"]=>
204  int(1)
205  ["TWO"]=>
206  int(2)
207  ["THREE"]=>
208  int(3)
209}
210
211-- Iteration 13 --
212array(3) {
213  ["one"]=>
214  int(1)
215  ["two"]=>
216  int(2)
217  ["three"]=>
218  int(3)
219}
220
221-- Iteration 14 --
222array(3) {
223  ["ONE"]=>
224  int(1)
225  ["TWO"]=>
226  int(2)
227  ["THREE"]=>
228  int(3)
229}
230
231-- Iteration 15 --
232array(3) {
233  ["one"]=>
234  int(1)
235  ["two"]=>
236  int(2)
237  ["three"]=>
238  int(3)
239}
240
241-- Iteration 16 --
242
243Warning: array_change_key_case() expects parameter 2 to be integer, string given in %s on line %d
244NULL
245
246-- Iteration 17 --
247
248Warning: array_change_key_case() expects parameter 2 to be integer, string given in %s on line %d
249NULL
250
251-- Iteration 18 --
252
253Warning: array_change_key_case() expects parameter 2 to be integer, array given in %s on line %d
254NULL
255
256-- Iteration 19 --
257
258Warning: array_change_key_case() expects parameter 2 to be integer, string given in %s on line %d
259NULL
260
261-- Iteration 20 --
262
263Warning: array_change_key_case() expects parameter 2 to be integer, string given in %s on line %d
264NULL
265
266-- Iteration 21 --
267
268Warning: array_change_key_case() expects parameter 2 to be integer, string given in %s on line %d
269NULL
270
271-- Iteration 22 --
272array(3) {
273  ["one"]=>
274  int(1)
275  ["two"]=>
276  int(2)
277  ["three"]=>
278  int(3)
279}
280
281-- Iteration 23 --
282array(3) {
283  ["one"]=>
284  int(1)
285  ["two"]=>
286  int(2)
287  ["three"]=>
288  int(3)
289}
290Done
291