1--TEST-- 2Test strtr() function : usage variations - unexpected inputs for 'from' argument 3--FILE-- 4<?php 5/* Test strtr() function: with unexpected inputs for 'from' 6 * and expected type for 'str' & 'to' arguments 7*/ 8 9echo "*** Testing strtr() function: with unexpected inputs for 'from' ***\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 values for 'from' 25$from_arr = array ( 26 27 // integer values 28/*1*/ 0, 29 1, 30 -2, 31 32 // float values 33/*4*/ 10.5, 34 -20.5, 35 10.1234567e10, 36 37 // array values 38/*7*/ array(), 39 array(0), 40 array(1, 2), 41 42 // boolean values 43/*10*/ true, 44 false, 45 TRUE, 46 FALSE, 47 48 // null values 49/*14*/ NULL, 50 null, 51 52 // objects 53/*16*/ new sample(), 54 55 // resource 56/*17*/ $file_handle, 57); 58 59//defining 'to' argument 60$to = "atm012"; 61 62// loop through with each element of the $from array to test strtr() function 63$count = 1; 64for($index = 0; $index < count($from_arr); $index++) { 65 echo "-- Iteration $count --\n"; 66 $from = $from_arr[$index]; 67 try { 68 var_dump(strtr($str, $from, $to)); 69 } catch (TypeError $exception) { 70 echo $exception->getMessage() . "\n"; 71 } 72 $count++; 73} 74 75fclose($file_handle); //closing the file handle 76?> 77--EXPECTF-- 78*** Testing strtr() function: with unexpected inputs for 'from' *** 79-- Iteration 1 -- 80string(6) "a12atm" 81-- Iteration 2 -- 82string(6) "0a2atm" 83-- Iteration 3 -- 84string(6) "01tatm" 85-- Iteration 4 -- 86string(6) "ta2atm" 87-- Iteration 5 -- 88string(6) "m1tatm" 89-- Iteration 6 -- 90string(6) "tm0atm" 91-- Iteration 7 -- 92strtr(): Argument #2 ($from) must be of type string, array given 93-- Iteration 8 -- 94strtr(): Argument #2 ($from) must be of type string, array given 95-- Iteration 9 -- 96strtr(): Argument #2 ($from) must be of type string, array given 97-- Iteration 10 -- 98string(6) "0a2atm" 99-- Iteration 11 -- 100string(6) "012atm" 101-- Iteration 12 -- 102string(6) "0a2atm" 103-- Iteration 13 -- 104string(6) "012atm" 105-- Iteration 14 -- 106 107Deprecated: strtr(): Passing null to parameter #2 ($from) of type array|string is deprecated in %s on line %d 108string(6) "012atm" 109-- Iteration 15 -- 110 111Deprecated: strtr(): Passing null to parameter #2 ($from) of type array|string is deprecated in %s on line %d 112string(6) "012atm" 113-- Iteration 16 -- 114string(6) "012ttm" 115-- Iteration 17 -- 116strtr(): Argument #2 ($from) must be of type array|string, resource given 117