1--TEST--
2Test array_shift() function : usage variations - Pass array with different data types as keys
3--FILE--
4<?php
5/*
6 * Pass arrays with different data types as keys to test how array_shift() re-assigns keys
7 */
8
9echo "*** Testing array_shift() : usage variations ***\n";
10
11//get an unset variable
12$unset_var = 10;
13unset ($unset_var);
14
15// heredoc string
16$heredoc = <<<EOT
17hello world
18EOT;
19
20// unexpected values to be passed to $stack argument
21$inputs = array(
22
23       // int data
24/*1*/  'int' => array(
25       0 => 'zero',
26       1 => 'one',
27       12345 => 'positive',
28       -2345 => 'negative',
29       ),
30
31       // float data
32/*2*/  'float' => array(
33       10.5 => 'positive',
34       -10.5 => 'negative',
35       .5 => 'half',
36       ),
37
38/*3*/  'extreme floats' => array(
39       12.3456789000e10 => 'large',
40       12.3456789000E-10 => 'small',
41       ),
42
43       // null data
44/*4*/  'null uppercase' => array(
45       NULL => 'null 1',
46       ),
47
48/*5*/  'null lowercase' => array(
49       null => 'null 2',
50       ),
51
52       // boolean data
53/*6*/  'bool lowercase' => array(
54       true => 'lowert',
55       false => 'lowerf',
56       ),
57
58/*7*/  'bool uppercase' => array(
59       TRUE => 'uppert',
60       FALSE => 'upperf',
61       ),
62
63       // empty data
64/*8*/  'empty double quotes' => array(
65       "" => 'emptyd',
66       ),
67
68/*9*/  'empty single quotes' => array(
69       '' => 'emptys',
70       ),
71
72       // string data
73/*10*/ 'string' => array(
74       "stringd" => 'stringd',
75       'strings' => 'strings',
76       $heredoc => 'stringh',
77       ),
78
79       // undefined data
80/*11*/ 'undefined' => array(
81       @$undefined_var => 'undefined',
82       ),
83
84       // unset data
85/*12*/ 'unset' => array(
86       @$unset_var => 'unset',
87       ),
88);
89
90// loop through each element of $inputs to check the behavior of array_shift()
91$iterator = 1;
92foreach($inputs as $key => $input) {
93  echo "\n-- Iteration $iterator : $key data --\n";
94  var_dump( array_shift($input) );
95  var_dump($input);
96  $iterator++;
97};
98
99echo "Done";
100?>
101--EXPECT--
102*** Testing array_shift() : usage variations ***
103
104-- Iteration 1 : int data --
105string(4) "zero"
106array(3) {
107  [0]=>
108  string(3) "one"
109  [1]=>
110  string(8) "positive"
111  [2]=>
112  string(8) "negative"
113}
114
115-- Iteration 2 : float data --
116string(8) "positive"
117array(2) {
118  [0]=>
119  string(8) "negative"
120  [1]=>
121  string(4) "half"
122}
123
124-- Iteration 3 : extreme floats data --
125string(5) "large"
126array(1) {
127  [0]=>
128  string(5) "small"
129}
130
131-- Iteration 4 : null uppercase data --
132string(6) "null 1"
133array(0) {
134}
135
136-- Iteration 5 : null lowercase data --
137string(6) "null 2"
138array(0) {
139}
140
141-- Iteration 6 : bool lowercase data --
142string(6) "lowert"
143array(1) {
144  [0]=>
145  string(6) "lowerf"
146}
147
148-- Iteration 7 : bool uppercase data --
149string(6) "uppert"
150array(1) {
151  [0]=>
152  string(6) "upperf"
153}
154
155-- Iteration 8 : empty double quotes data --
156string(6) "emptyd"
157array(0) {
158}
159
160-- Iteration 9 : empty single quotes data --
161string(6) "emptys"
162array(0) {
163}
164
165-- Iteration 10 : string data --
166string(7) "stringd"
167array(2) {
168  ["strings"]=>
169  string(7) "strings"
170  ["hello world"]=>
171  string(7) "stringh"
172}
173
174-- Iteration 11 : undefined data --
175string(9) "undefined"
176array(0) {
177}
178
179-- Iteration 12 : unset data --
180string(5) "unset"
181array(0) {
182}
183Done
184