1--TEST-- 2Test mb_strtoupper() function : usage varitations - Pass different data types as $encoding arg 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_strtoupper') or die("skip mb_strtoupper() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* Prototype : string mb_strtoupper(string $sourcestring [, string $encoding] 11 * Description: Returns a uppercased version of $sourcestring 12 * Source code: ext/mbstring/mbstring.c 13 */ 14 15/* 16 * Pass different data types as $encoding argument to mb_strtoupper() to test behaviour 17 * Where possible, 'UTF-8' is entered as string value 18 */ 19 20echo "*** Testing mb_strtoupper() : usage variations ***\n"; 21 22// Initialise function arguments not being substituted 23$sourcestring = b'Hello, World'; 24 25//get an unset variable 26$unset_var = 10; 27unset ($unset_var); 28 29// get a class 30class classA 31{ 32 public function __toString() { 33 return "UTF-8"; 34 } 35} 36 37// heredoc string 38$heredoc = <<<EOT 39UTF-8 40EOT; 41 42// get a resource variable 43$fp = fopen(__FILE__, "r"); 44 45// unexpected values to be passed to $encoding argument 46$inputs = array( 47 48 // int data 49/*1*/ 0, 50 1, 51 12345, 52 -2345, 53 54 // float data 55/*5*/ 10.5, 56 -10.5, 57 12.3456789000e10, 58 12.3456789000E-10, 59 .5, 60 61 // null data 62/*10*/ NULL, 63 null, 64 65 // boolean data 66/*12*/ true, 67 false, 68 TRUE, 69 FALSE, 70 71 // empty data 72/*16*/ "", 73 '', 74 75 // string data 76/*18*/ "UTF-8", 77 'UTF-8', 78 $heredoc, 79 80 // object data 81/*21*/ new classA(), 82 83 // undefined data 84/*22*/ @$undefined_var, 85 86 // unset data 87/*23*/ @$unset_var, 88 89 // resource variable 90/*24*/ $fp 91); 92 93// loop through each element of $inputs to check the behavior of mb_strtoupper() 94$iterator = 1; 95foreach($inputs as $input) { 96 echo "\n-- Iteration $iterator --\n"; 97 $res = mb_strtoupper($sourcestring, $input); 98 if ($res === false || $res == NULL) { 99 var_dump($res); 100 } 101 else { 102 var_dump(bin2hex($res)); 103 } 104 $iterator++; 105}; 106 107fclose($fp); 108 109echo "Done"; 110?> 111 112--EXPECTF-- 113*** Testing mb_strtoupper() : usage variations *** 114 115-- Iteration 1 -- 116 117Warning: mb_strtoupper(): Unknown encoding "0" in %s on line %d 118bool(false) 119 120-- Iteration 2 -- 121 122Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d 123bool(false) 124 125-- Iteration 3 -- 126 127Warning: mb_strtoupper(): Unknown encoding "12345" in %s on line %d 128bool(false) 129 130-- Iteration 4 -- 131 132Warning: mb_strtoupper(): Unknown encoding "-2345" in %s on line %d 133bool(false) 134 135-- Iteration 5 -- 136 137Warning: mb_strtoupper(): Unknown encoding "10.5" in %s on line %d 138bool(false) 139 140-- Iteration 6 -- 141 142Warning: mb_strtoupper(): Unknown encoding "-10.5" in %s on line %d 143bool(false) 144 145-- Iteration 7 -- 146 147Warning: mb_strtoupper(): Unknown encoding "123456789000" in %s on line %d 148bool(false) 149 150-- Iteration 8 -- 151 152Warning: mb_strtoupper(): Unknown encoding "1.23456789E-9" in %s on line %d 153bool(false) 154 155-- Iteration 9 -- 156 157Warning: mb_strtoupper(): Unknown encoding "0.5" in %s on line %d 158bool(false) 159 160-- Iteration 10 -- 161 162Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d 163bool(false) 164 165-- Iteration 11 -- 166 167Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d 168bool(false) 169 170-- Iteration 12 -- 171 172Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d 173bool(false) 174 175-- Iteration 13 -- 176 177Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d 178bool(false) 179 180-- Iteration 14 -- 181 182Warning: mb_strtoupper(): Unknown encoding "1" in %s on line %d 183bool(false) 184 185-- Iteration 15 -- 186 187Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d 188bool(false) 189 190-- Iteration 16 -- 191 192Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d 193bool(false) 194 195-- Iteration 17 -- 196 197Warning: mb_strtoupper(): Unknown encoding "" in %s on line %d 198bool(false) 199 200-- Iteration 18 -- 201string(24) "48454c4c4f2c20574f524c44" 202 203-- Iteration 19 -- 204string(24) "48454c4c4f2c20574f524c44" 205 206-- Iteration 20 -- 207string(24) "48454c4c4f2c20574f524c44" 208 209-- Iteration 21 -- 210string(24) "48454c4c4f2c20574f524c44" 211 212-- Iteration 22 -- 213 214Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d 215bool(false) 216 217-- Iteration 23 -- 218 219Warning: mb_strtoupper(): Unknown encoding "(null)" in %s on line %d 220bool(false) 221 222-- Iteration 24 -- 223 224Warning: mb_strtoupper() expects parameter 2 to be string, resource given in %s on line %d 225NULL 226Done