1--TEST-- 2Test array_combine() function : usage variations - unexpected values for 'values' argument 3--FILE-- 4<?php 5/* Prototype : array array_combine(array $keys, array $values) 6 * Description: Creates an array by using the elements of the first parameter as keys 7 * and the elements of the second as the corresponding values 8 * Source code: ext/standard/array.c 9*/ 10 11/* 12* Testing array_combine() function by passing values to $values argument other than arrays 13* and see that function emits proper warning messages wherever expected. 14* The $keys argument passed is a fixed array. 15*/ 16 17echo "*** Testing array_combine() : Passing non-array values to \$values argument ***\n"; 18 19// Initialize $keys array 20$keys = array(1, 2); 21 22//get an unset variable 23$unset_var = 10; 24unset($unset_var); 25 26// get a class 27class classA 28{ 29 public function __toString() { 30 return "Class A object"; 31 } 32} 33 34// heredoc string 35$heredoc = <<<EOT 36hello world 37EOT; 38 39// get a resource variable 40$fp = fopen(__FILE__, "r"); 41 42// unexpected values to be passed to $values argument 43$values_passed = array( 44 45 // int data 46/*1*/ 0, 47 1, 48 12345, 49 -2345, 50 51 // float data 52/*5*/ 10.5, 53 -10.5, 54 12.3456789000e10, 55 12.3456789000E-10, 56 .5, 57 58 // null data 59/*10*/ NULL, 60 null, 61 62 // boolean data 63/*12*/ true, 64 false, 65 TRUE, 66 FALSE, 67 68 // empty data 69/*16*/ "", 70 '', 71 72 // string data 73/*18*/ "string", 74 'string', 75 $heredoc, 76 77 // object data 78/*21*/ new classA(), 79 80 // undefined data 81/*22*/ @$undefined_var, 82 83 // unset data 84/*23*/ @$unset_var, 85 86 // resource variable 87/*24*/ $fp 88); 89 90// loop through each element within $values_passed to check the behavior of array_combine() 91$iterator = 1; 92foreach($values_passed as $values) { 93 echo "-- Iteration $iterator --\n"; 94 var_dump( array_combine($keys,$values) ); 95 $iterator++; 96}; 97 98echo "Done"; 99?> 100--EXPECTF-- 101*** Testing array_combine() : Passing non-array values to $values argument *** 102-- Iteration 1 -- 103 104Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d 105NULL 106-- Iteration 2 -- 107 108Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d 109NULL 110-- Iteration 3 -- 111 112Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d 113NULL 114-- Iteration 4 -- 115 116Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d 117NULL 118-- Iteration 5 -- 119 120Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d 121NULL 122-- Iteration 6 -- 123 124Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d 125NULL 126-- Iteration 7 -- 127 128Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d 129NULL 130-- Iteration 8 -- 131 132Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d 133NULL 134-- Iteration 9 -- 135 136Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d 137NULL 138-- Iteration 10 -- 139 140Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d 141NULL 142-- Iteration 11 -- 143 144Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d 145NULL 146-- Iteration 12 -- 147 148Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d 149NULL 150-- Iteration 13 -- 151 152Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d 153NULL 154-- Iteration 14 -- 155 156Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d 157NULL 158-- Iteration 15 -- 159 160Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d 161NULL 162-- Iteration 16 -- 163 164Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d 165NULL 166-- Iteration 17 -- 167 168Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d 169NULL 170-- Iteration 18 -- 171 172Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d 173NULL 174-- Iteration 19 -- 175 176Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d 177NULL 178-- Iteration 20 -- 179 180Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d 181NULL 182-- Iteration 21 -- 183 184Warning: array_combine() expects parameter 2 to be array, object given in %s on line %d 185NULL 186-- Iteration 22 -- 187 188Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d 189NULL 190-- Iteration 23 -- 191 192Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d 193NULL 194-- Iteration 24 -- 195 196Warning: array_combine() expects parameter 2 to be array, resource given in %s on line %d 197NULL 198Done 199