1--TEST-- 2Test mb_substitute_character() function : usage variation 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_substitute_character') or die("skip mb_substitute_character() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* Prototype : mixed mb_substitute_character([mixed substchar]) 11 * Description: Sets the current substitute_character or returns the current substitute_character 12 * Source code: ext/mbstring/mbstring.c 13 * Alias to functions: 14 */ 15 16echo "*** Testing mb_substitute_character() : usage variation ***\n"; 17 18// Define error handler 19function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { 20 if (error_reporting() != 0) { 21 // report non-silenced errors 22 echo "Error: $err_no - $err_msg, $filename($linenum)\n"; 23 } 24} 25set_error_handler('test_error_handler'); 26 27// Initialise function arguments not being substituted (if any) 28 29//get an unset variable 30$unset_var = 10; 31unset ($unset_var); 32 33// define some classes 34class classWithToString 35{ 36 public function __toString() { 37 return "Class A object"; 38 } 39} 40 41class classWithoutToString 42{ 43} 44 45// heredoc string 46$heredoc = <<<EOT 47hello world 48EOT; 49 50// get a resource variable 51$fp = fopen(__FILE__, "r"); 52 53// add arrays 54$index_array = array (1, 2, 3); 55$assoc_array = array ('one' => 1, 'two' => 2); 56 57//array of values to iterate over 58$inputs = array( 59 60 // int data 61 'int 0' => 0, 62 'int 1' => 1, 63 'int 12345' => 12345, 64 'int -12345' => -2345, 65 66 // float data 67 'float 10.5' => 10.5, 68 'float -10.5' => -10.5, 69 'float 12.3456789000e10' => 12.3456789000e10, 70 'float -12.3456789000e10' => -12.3456789000e10, 71 'float .5' => .5, 72 73 // array data 74 'empty array' => array(), 75 'int indexed array' => $index_array, 76 'associative array' => $assoc_array, 77 'nested arrays' => array('foo', $index_array, $assoc_array), 78 79 // null data 80 'uppercase NULL' => NULL, 81 'lowercase null' => null, 82 83 // boolean data 84 'lowercase true' => true, 85 'lowercase false' =>false, 86 'uppercase TRUE' =>TRUE, 87 'uppercase FALSE' =>FALSE, 88 89 // empty data 90 'empty string DQ' => "", 91 'empty string SQ' => '', 92 93 // string data 94 'string DQ' => "string", 95 'string SQ' => 'string', 96 'mixed case string' => "sTrInG", 97 'heredoc' => $heredoc, 98 99 // object data 100 'instance of classWithToString' => new classWithToString(), 101 'instance of classWithoutToString' => new classWithoutToString(), 102 103 // undefined data 104 'undefined var' => @$undefined_var, 105 106 // unset data 107 'unset var' => @$unset_var, 108); 109 110// loop through each element of the array for substchar 111 112mb_internal_encoding('utf-8'); 113foreach($inputs as $key =>$value) { 114 echo "\n--$key--\n"; 115 var_dump( mb_substitute_character($value) ); 116}; 117 118fclose($fp); 119 120?> 121===DONE=== 122--EXPECTF-- 123*** Testing mb_substitute_character() : usage variation *** 124 125--int 0-- 126Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 127bool(false) 128 129--int 1-- 130bool(true) 131 132--int 12345-- 133bool(true) 134 135--int -12345-- 136Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 137bool(false) 138 139--float 10.5-- 140bool(true) 141 142--float -10.5-- 143Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 144bool(false) 145 146--float 12.3456789000e10-- 147Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 148bool(false) 149 150--float -12.3456789000e10-- 151Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 152bool(false) 153 154--float .5-- 155Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 156bool(false) 157 158--empty array-- 159Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 160bool(false) 161 162--int indexed array-- 163bool(true) 164 165--associative array-- 166bool(true) 167 168--nested arrays-- 169bool(true) 170 171--uppercase NULL-- 172Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 173bool(false) 174 175--lowercase null-- 176Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 177bool(false) 178 179--lowercase true-- 180bool(true) 181 182--lowercase false-- 183Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 184bool(false) 185 186--uppercase TRUE-- 187bool(true) 188 189--uppercase FALSE-- 190Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 191bool(false) 192 193--empty string DQ-- 194bool(true) 195 196--empty string SQ-- 197bool(true) 198 199--string DQ-- 200Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 201bool(false) 202 203--string SQ-- 204Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 205bool(false) 206 207--mixed case string-- 208Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 209bool(false) 210 211--heredoc-- 212Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 213bool(false) 214 215--instance of classWithToString-- 216Error: 8 - Object of class classWithToString could not be converted to int, %s(%d) 217bool(true) 218 219--instance of classWithoutToString-- 220Error: 8 - Object of class classWithoutToString could not be converted to int, %s(%d) 221bool(true) 222 223--undefined var-- 224Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 225bool(false) 226 227--unset var-- 228Error: 2 - mb_substitute_character(): Unknown character., %s(%d) 229bool(false) 230===DONE=== 231 232