1--TEST-- 2Test mb_strtoupper() function : usage varitations - pass different data types as $sourcestring 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 * 17 * Pass different data types as $sourcestring argument to mb_strtoupper to test behaviour 18 */ 19 20echo "*** Testing mb_strtoupper() : usage variations ***\n"; 21 22// Initialise function arguments not being substituted 23 24//get an unset variable 25$unset_var = 10; 26unset ($unset_var); 27 28// get a class 29class classA 30{ 31 public function __toString() { 32 return "Class A object"; 33 } 34} 35 36// heredoc string 37$heredoc = <<<EOT 38Hello, World 39EOT; 40 41// get a resource variable 42$fp = fopen(__FILE__, "r"); 43 44// unexpected values to be passed to $sourcestring argument 45$inputs = array( 46 47 // int data 48/*1*/ 0, 49 1, 50 12345, 51 -2345, 52 53 // float data 54/*5*/ 10.5, 55 -10.5, 56 12.3456789000e10, 57 12.3456789000E-10, 58 .5, 59 60 // null data 61/*10*/ NULL, 62 null, 63 64 // boolean data 65/*12*/ true, 66 false, 67 TRUE, 68 FALSE, 69 70 // empty data 71/*16*/ "", 72 '', 73 74 // string data 75/*18*/ "String", 76 'String', 77 $heredoc, 78 79 // object data 80/*21*/ new classA(), 81 82 // undefined data 83/*22*/ @$undefined_var, 84 85 // unset data 86/*23*/ @$unset_var, 87 88 // resource variable 89/*24*/ $fp 90); 91 92// loop through each element of $inputs to check the behavior of mb_strtoupper() 93$iterator = 1; 94foreach($inputs as $input) { 95 echo "\n-- Iteration $iterator --\n"; 96 var_dump( mb_strtoupper($input) ); 97 $iterator++; 98}; 99 100fclose($fp); 101 102echo "Done"; 103?> 104 105--EXPECTF-- 106*** Testing mb_strtoupper() : usage variations *** 107 108-- Iteration 1 -- 109string(1) "0" 110 111-- Iteration 2 -- 112string(1) "1" 113 114-- Iteration 3 -- 115string(5) "12345" 116 117-- Iteration 4 -- 118string(5) "-2345" 119 120-- Iteration 5 -- 121string(4) "10.5" 122 123-- Iteration 6 -- 124string(5) "-10.5" 125 126-- Iteration 7 -- 127string(12) "123456789000" 128 129-- Iteration 8 -- 130string(13) "1.23456789E-9" 131 132-- Iteration 9 -- 133string(3) "0.5" 134 135-- Iteration 10 -- 136string(0) "" 137 138-- Iteration 11 -- 139string(0) "" 140 141-- Iteration 12 -- 142string(1) "1" 143 144-- Iteration 13 -- 145string(0) "" 146 147-- Iteration 14 -- 148string(1) "1" 149 150-- Iteration 15 -- 151string(0) "" 152 153-- Iteration 16 -- 154string(0) "" 155 156-- Iteration 17 -- 157string(0) "" 158 159-- Iteration 18 -- 160string(6) "STRING" 161 162-- Iteration 19 -- 163string(6) "STRING" 164 165-- Iteration 20 -- 166string(12) "HELLO, WORLD" 167 168-- Iteration 21 -- 169string(14) "CLASS A OBJECT" 170 171-- Iteration 22 -- 172string(0) "" 173 174-- Iteration 23 -- 175string(0) "" 176 177-- Iteration 24 -- 178 179Warning: mb_strtoupper() expects parameter 1 to be string, resource given in %s on line %d 180NULL 181Done