1--TEST-- 2Test array_push() function : usage variations - Pass different data types as $var arg 3--FILE-- 4<?php 5/* 6 * Pass different data types as $var argument to array_push to test behaviour 7 */ 8 9echo "*** Testing array_push() : usage variations ***\n"; 10 11// Initialise function arguments not being substituted 12$stack = array (1, 2); 13 14//get an unset variable 15$unset_var = 10; 16unset ($unset_var); 17 18// get a class 19class classA 20{ 21 public function __toString() { 22 return "Class A object"; 23 } 24} 25 26// heredoc string 27$heredoc = <<<EOT 28hello world 29EOT; 30 31// get a resource variable 32$fp = fopen(__FILE__, "r"); 33 34// unexpected values to be passed to $var 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*/ "string", 67 'string', 68 $heredoc, 69 70 // object data 71/*22*/ new classA(), 72 73 // undefined data 74/*23*/ @$undefined_var, 75 76 // unset data 77/*24*/ @$unset_var, 78 79 // resource variable 80/*25*/ $fp 81); 82 83// loop through each element of $inputs to check the behavior of array_push() 84$iterator = 1; 85foreach($inputs as $input) { 86 echo "\n-- Iteration $iterator --\n"; 87 $temp_array = $stack; 88 var_dump( array_push($temp_array, $input) ); 89 $iterator++; 90}; 91 92fclose($fp); 93 94echo "Done"; 95?> 96--EXPECT-- 97*** Testing array_push() : usage variations *** 98 99-- Iteration 1 -- 100int(3) 101 102-- Iteration 2 -- 103int(3) 104 105-- Iteration 3 -- 106int(3) 107 108-- Iteration 4 -- 109int(3) 110 111-- Iteration 5 -- 112int(3) 113 114-- Iteration 6 -- 115int(3) 116 117-- Iteration 7 -- 118int(3) 119 120-- Iteration 8 -- 121int(3) 122 123-- Iteration 9 -- 124int(3) 125 126-- Iteration 10 -- 127int(3) 128 129-- Iteration 11 -- 130int(3) 131 132-- Iteration 12 -- 133int(3) 134 135-- Iteration 13 -- 136int(3) 137 138-- Iteration 14 -- 139int(3) 140 141-- Iteration 15 -- 142int(3) 143 144-- Iteration 16 -- 145int(3) 146 147-- Iteration 17 -- 148int(3) 149 150-- Iteration 18 -- 151int(3) 152 153-- Iteration 19 -- 154int(3) 155 156-- Iteration 20 -- 157int(3) 158 159-- Iteration 21 -- 160int(3) 161 162-- Iteration 22 -- 163int(3) 164 165-- Iteration 23 -- 166int(3) 167 168-- Iteration 24 -- 169int(3) 170 171-- Iteration 25 -- 172int(3) 173Done 174