1--TEST--
2Test array_shift() function : usage variations - Pass arrays of different data types
3--FILE--
4<?php
5/* Prototype  : mixed array_shift(array &$stack)
6 * Description: Pops an element off the beginning of the array
7 * Source code: ext/standard/array.c
8 */
9
10/*
11 * Pass arrays where values are of one data type to test behaviour of array_shift()
12 */
13
14echo "*** Testing array_shift() : usage variations ***\n";
15
16
17//get an unset variable
18$unset_var = 10;
19unset ($unset_var);
20
21// get a class
22class classA
23{
24  public function __toString() {
25    return "Class A object";
26  }
27}
28
29// heredoc string
30$heredoc = <<<EOT
31hello world
32EOT;
33
34// get a resource variable
35$fp = fopen(__FILE__, "r");
36
37// arrays of different data types to be passed to $stack argument
38$inputs = array(
39
40       // int data
41/*1*/  'int' => array(
42	   0,
43       1,
44       12345,
45       -2345,
46       ),
47
48       // float data
49/*2*/  'float' => array(
50       10.5,
51       -10.5,
52       12.3456789000e10,
53       12.3456789000E-10,
54       .5,
55       ),
56
57       // null data
58/*3*/ 'null' => array(
59       NULL,
60       null,
61       ),
62
63       // boolean data
64/*4*/ 'bool' => array(
65       true,
66       false,
67       TRUE,
68       FALSE,
69       ),
70
71       // empty data
72/*5*/ 'empty string' => array(
73       "",
74       '',
75       ),
76
77/*6*/ 'empty array' => array(
78       ),
79
80       // string data
81/*7*/ 'string' => array(
82       "string",
83       'string',
84       $heredoc,
85       ),
86
87       // object data
88/*8*/ 'object' => array(
89       new classA(),
90       ),
91
92       // undefined data
93/*9*/ 'undefined' => array(
94       @$undefined_var,
95       ),
96
97       // unset data
98/*10*/ 'unset' => array(
99       @$unset_var,
100       ),
101
102       // resource variable
103/*11*/ 'resource' => array(
104       $fp
105       ),
106);
107
108// loop through each element of $inputs to check the behavior of array_shift
109$iterator = 1;
110foreach($inputs as $key => $input) {
111  echo "\n-- Iteration $iterator: $key data --\n";
112  var_dump( array_shift($input) );
113  var_dump($input);
114  $iterator++;
115};
116
117fclose($fp);
118
119
120echo "Done";
121?>
122--EXPECTF--
123*** Testing array_shift() : usage variations ***
124
125-- Iteration 1: int data --
126int(0)
127array(3) {
128  [0]=>
129  int(1)
130  [1]=>
131  int(12345)
132  [2]=>
133  int(-2345)
134}
135
136-- Iteration 2: float data --
137float(10.5)
138array(4) {
139  [0]=>
140  float(-10.5)
141  [1]=>
142  float(123456789000)
143  [2]=>
144  float(1.23456789E-9)
145  [3]=>
146  float(0.5)
147}
148
149-- Iteration 3: null data --
150NULL
151array(1) {
152  [0]=>
153  NULL
154}
155
156-- Iteration 4: bool data --
157bool(true)
158array(3) {
159  [0]=>
160  bool(false)
161  [1]=>
162  bool(true)
163  [2]=>
164  bool(false)
165}
166
167-- Iteration 5: empty string data --
168string(0) ""
169array(1) {
170  [0]=>
171  string(0) ""
172}
173
174-- Iteration 6: empty array data --
175NULL
176array(0) {
177}
178
179-- Iteration 7: string data --
180string(6) "string"
181array(2) {
182  [0]=>
183  string(6) "string"
184  [1]=>
185  string(11) "hello world"
186}
187
188-- Iteration 8: object data --
189object(classA)#%d (0) {
190}
191array(0) {
192}
193
194-- Iteration 9: undefined data --
195NULL
196array(0) {
197}
198
199-- Iteration 10: unset data --
200NULL
201array(0) {
202}
203
204-- Iteration 11: resource data --
205resource(%d) of type (stream)
206array(0) {
207}
208Done