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