Return to strtr_variation6.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test strtr() function : usage variations - unexpected inputs for 'from' 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 'from' 12: * and expected type for 'str' & 'to' arguments 13: */ 14: 15: echo "*** Testing strtr() function: with unexpected inputs for 'from' ***\n"; 16: 17: //get an unset variable 18: $unset_var = 'string_val'; 19: unset($unset_var); 20: 21: //defining a class 22: class 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 values for 'from' 35: $from_arr = array ( 36: 37: // integer values 38: /*1*/ 0, 39: 1, 40: -2, 41: 42: // float values 43: /*4*/ 10.5, 44: -20.5, 45: 10.1234567e10, 46: 47: // array values 48: /*7*/ array(), 49: array(0), 50: array(1, 2), 51: 52: // boolean values 53: /*10*/ true, 54: false, 55: TRUE, 56: FALSE, 57: 58: // null vlaues 59: /*14*/ NULL, 60: null, 61: 62: // objects 63: /*16*/ new sample(), 64: 65: // resource 66: /*17*/ $file_handle, 67: 68: // undefined variable 69: /*18*/ @$undefined_var, 70: 71: // unset variable 72: /*19*/ @$unset_var 73: ); 74: 75: //defining 'to' argument 76: $to = "atm012"; 77: 78: // loop through with each element of the $from array to test strtr() function 79: $count = 1; 80: for($index = 0; $index < count($from_arr); $index++) { 81: echo "-- Iteration $count --\n"; 82: $from = $from_arr[$index]; 83: var_dump( strtr($str, $from, $to) ); 84: $count ++; 85: } 86: 87: fclose($file_handle); //closing the file handle 88: ?> 89: ===DONE=== 90: --EXPECTF-- 91: *** Testing strtr() function: with unexpected inputs for 'from' *** 92: -- Iteration 1 -- 93: string(6) "a12atm" 94: -- Iteration 2 -- 95: string(6) "0a2atm" 96: -- Iteration 3 -- 97: string(6) "01tatm" 98: -- Iteration 4 -- 99: string(6) "ta2atm" 100: -- Iteration 5 -- 101: string(6) "m1tatm" 102: -- Iteration 6 -- 103: string(6) "tm0atm" 104: -- Iteration 7 -- 105: 106: Notice: Array to string conversion in %s on line %d 107: string(6) "0120tm" 108: -- Iteration 8 -- 109: 110: Notice: Array to string conversion in %s on line %d 111: string(6) "0120tm" 112: -- Iteration 9 -- 113: 114: Notice: Array to string conversion in %s on line %d 115: string(6) "0120tm" 116: -- Iteration 10 -- 117: string(6) "0a2atm" 118: -- Iteration 11 -- 119: string(6) "012atm" 120: -- Iteration 12 -- 121: string(6) "0a2atm" 122: -- Iteration 13 -- 123: string(6) "012atm" 124: -- Iteration 14 -- 125: string(6) "012atm" 126: -- Iteration 15 -- 127: string(6) "012atm" 128: -- Iteration 16 -- 129: string(6) "012ttm" 130: -- Iteration 17 -- 131: string(6) "012atm" 132: -- Iteration 18 -- 133: string(6) "012atm" 134: -- Iteration 19 -- 135: string(6) "012atm" 136: ===DONE===