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