1--TEST-- 2Test strtr() function : usage variations - unexpected inputs for 'replace_pairs' argument 3--FILE-- 4<?php 5/* Prototype : string strtr(string $str, string $from[, string $to]); 6 string strtr(string $str, array $replace_pairs); 7 * Description: Translates characters in str using given translation tables 8 * Source code: ext/standard/string.c 9*/ 10 11/* Test strtr() function: with unexpected inputs for 'replace_pairs' 12 * and expected type for 'str' arguments 13*/ 14 15echo "*** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***\n"; 16 17//get an unset variable 18$unset_var = 'string_val'; 19unset($unset_var); 20 21//defining a class 22class sample { 23 public function __toString() { 24 return "sample object"; 25 } 26} 27 28//getting the resource 29$file_handle = fopen(__FILE__, "r"); 30 31//defining 'str' argument 32$str = "012atm"; 33 34// array of inputs for 'replace_pairs' argument 35$replace_pairs_arr = array ( 36 37 // integer values 38 0, 39 1, 40 -2, 41 42 // float values 43 10.5, 44 -20.5, 45 10.5e10, 46 47 // array values 48 array(), 49 array(0), 50 array(1, 2), 51 52 // boolean values 53 true, 54 false, 55 TRUE, 56 FALSE, 57 58 // null vlaues 59 NULL, 60 null, 61 62 // objects 63 new sample(), 64 65 // resource 66 $file_handle, 67 68 // undefined variable 69 @$undefined_var, 70 71 // unset variable 72 @$unset_var 73); 74 75// loop through with each element of the $replace_pairs array to test strtr() function 76$count = 1; 77for($index = 0; $index < count($replace_pairs_arr); $index++) { 78 echo "\n-- Iteration $count --\n"; 79 $replace_pairs = $replace_pairs_arr[$index]; 80 var_dump( strtr($str, $replace_pairs) ); 81 $count ++; 82} 83 84fclose($file_handle); //closing the file handle 85 86echo "*** Done ***"; 87?> 88--EXPECTF-- 89*** Testing strtr() function: with unexpected inputs for 'replace_pairs' *** 90 91-- Iteration 1 -- 92 93Warning: strtr(): The second argument is not an array in %s on line %d 94bool(false) 95 96-- Iteration 2 -- 97 98Warning: strtr(): The second argument is not an array in %s on line %d 99bool(false) 100 101-- Iteration 3 -- 102 103Warning: strtr(): The second argument is not an array in %s on line %d 104bool(false) 105 106-- Iteration 4 -- 107 108Warning: strtr(): The second argument is not an array in %s on line %d 109bool(false) 110 111-- Iteration 5 -- 112 113Warning: strtr(): The second argument is not an array in %s on line %d 114bool(false) 115 116-- Iteration 6 -- 117 118Warning: strtr(): The second argument is not an array in %s on line %d 119bool(false) 120 121-- Iteration 7 -- 122string(6) "012atm" 123 124-- Iteration 8 -- 125string(6) "012atm" 126 127-- Iteration 9 -- 128string(6) "122atm" 129 130-- Iteration 10 -- 131 132Warning: strtr(): The second argument is not an array in %s on line %d 133bool(false) 134 135-- Iteration 11 -- 136 137Warning: strtr(): The second argument is not an array in %s on line %d 138bool(false) 139 140-- Iteration 12 -- 141 142Warning: strtr(): The second argument is not an array in %s on line %d 143bool(false) 144 145-- Iteration 13 -- 146 147Warning: strtr(): The second argument is not an array in %s on line %d 148bool(false) 149 150-- Iteration 14 -- 151 152Warning: strtr(): The second argument is not an array in %s on line %d 153bool(false) 154 155-- Iteration 15 -- 156 157Warning: strtr(): The second argument is not an array in %s on line %d 158bool(false) 159 160-- Iteration 16 -- 161 162Warning: strtr(): The second argument is not an array in %s on line %d 163bool(false) 164 165-- Iteration 17 -- 166 167Warning: strtr(): The second argument is not an array in %s on line %d 168bool(false) 169 170-- Iteration 18 -- 171 172Warning: strtr(): The second argument is not an array in %s on line %d 173bool(false) 174 175-- Iteration 19 -- 176 177Warning: strtr(): The second argument is not an array in %s on line %d 178bool(false) 179*** Done *** 180