1--TEST-- 2Test strtr() function : usage variations - unexpected inputs for 'replace_pairs' argument 3--FILE-- 4<?php 5/* Test strtr() function: with unexpected inputs for 'replace_pairs' 6 * and expected type for 'str' arguments 7*/ 8 9echo "*** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***\n"; 10 11//defining a class 12class sample { 13 public function __toString() { 14 return "sample object"; 15 } 16} 17 18//getting the resource 19$file_handle = fopen(__FILE__, "r"); 20 21//defining 'str' argument 22$str = "012atm"; 23 24// array of inputs for 'replace_pairs' argument 25$replace_pairs_arr = array ( 26 27 // integer values 28 0, 29 1, 30 -2, 31 32 // float values 33 10.5, 34 -20.5, 35 10.5e10, 36 37 // array values 38 array(), 39 array(0), 40 array(1, 2), 41 42 // boolean values 43 true, 44 false, 45 TRUE, 46 FALSE, 47 48 // null values 49 NULL, 50 null, 51 52 // objects 53 new sample(), 54 55 // resource 56 $file_handle, 57); 58 59// loop through with each element of the $replace_pairs array to test strtr() function 60$count = 1; 61for($index = 0; $index < count($replace_pairs_arr); $index++) { 62 echo "\n-- Iteration $count --\n"; 63 $replace_pairs = $replace_pairs_arr[$index]; 64 try { 65 var_dump(strtr($str, $replace_pairs)); 66 } catch (TypeError $e) { 67 echo $e->getMessage() . "\n"; 68 } 69 70 $count ++; 71} 72 73fclose($file_handle); //closing the file handle 74 75echo "*** Done ***"; 76?> 77--EXPECTF-- 78*** Testing strtr() function: with unexpected inputs for 'replace_pairs' *** 79 80-- Iteration 1 -- 81strtr(): Argument #2 ($from) must be of type array, string given 82 83-- Iteration 2 -- 84strtr(): Argument #2 ($from) must be of type array, string given 85 86-- Iteration 3 -- 87strtr(): Argument #2 ($from) must be of type array, string given 88 89-- Iteration 4 -- 90strtr(): Argument #2 ($from) must be of type array, string given 91 92-- Iteration 5 -- 93strtr(): Argument #2 ($from) must be of type array, string given 94 95-- Iteration 6 -- 96strtr(): Argument #2 ($from) must be of type array, string given 97 98-- Iteration 7 -- 99string(6) "012atm" 100 101-- Iteration 8 -- 102string(6) "012atm" 103 104-- Iteration 9 -- 105string(6) "122atm" 106 107-- Iteration 10 -- 108strtr(): Argument #2 ($from) must be of type array, string given 109 110-- Iteration 11 -- 111strtr(): Argument #2 ($from) must be of type array, string given 112 113-- Iteration 12 -- 114strtr(): Argument #2 ($from) must be of type array, string given 115 116-- Iteration 13 -- 117strtr(): Argument #2 ($from) must be of type array, string given 118 119-- Iteration 14 -- 120 121Deprecated: strtr(): Passing null to parameter #2 ($from) of type array|string is deprecated in %s on line %d 122strtr(): Argument #2 ($from) must be of type array, string given 123 124-- Iteration 15 -- 125 126Deprecated: strtr(): Passing null to parameter #2 ($from) of type array|string is deprecated in %s on line %d 127strtr(): Argument #2 ($from) must be of type array, string given 128 129-- Iteration 16 -- 130strtr(): Argument #2 ($from) must be of type array, string given 131 132-- Iteration 17 -- 133strtr(): Argument #2 ($from) must be of type array|string, resource given 134*** Done *** 135