1--TEST-- 2"ucfirst()" function 3--INI-- 4precision=14 5--FILE-- 6<?php 7/* Make a string's first character uppercase */ 8 9echo "#### Basic and Various operations ####\n"; 10$str_array = array( 11 "testing ucfirst.", 12 "1.testing ucfirst", 13 "hELLO wORLD", 14 'hELLO wORLD', 15 "\0", // Null 16 "\x00", // Hex Null 17 "\x000", 18 "abcd", // double quoted string 19 'xyz', // single quoted string 20 somestring, // without quotes 21 "-3", 22 -3, 23 '-3.344', 24 -3.344, 25 NULL, 26 "NULL", 27 "0", 28 0, 29 TRUE, // bool type 30 "TRUE", 31 "1", 32 1, 33 1.234444, 34 FALSE, 35 "FALSE", 36 " ", 37 " ", 38 'b', // single char 39 '\t', // escape sequences 40 "\t", 41 "12", 42 "12twelve", // int + string 43 ); 44/* loop to test working of ucfirst with different values */ 45foreach ($str_array as $string) { 46 var_dump( ucfirst($string) ); 47} 48 49 50 51echo "\n#### Testing Miscelleneous inputs ####\n"; 52 53echo "--- Testing arrays ---"; 54$str_arr = array("hello", "?world", "!$%**()%**[][[[&@#~!", array()); 55var_dump( ucfirst($str_arr) ); 56 57echo "\n--- Testing objects ---\n"; 58/* we get "Recoverable fatal error: saying Object of class could not be converted 59 to string" by default when an object is passed instead of string: 60The error can be avoided by choosing the __toString magix method as follows: */ 61 62class stringable { 63 function __toString() { 64 return "hello, world"; 65 } 66} 67$obj_string = new stringable; 68 69var_dump(ucfirst("$obj_string")); 70 71 72echo "\n--- Testing Resources ---\n"; 73$filename1 = "dummy.txt"; 74$file1 = fopen($filename1, "w"); // creating new file 75 76/* getting resource type for file handle */ 77$string1 = get_resource_type($file1); 78$string2 = (int)get_resource_type($file1); // converting stream type to int 79 80/* $string1 is of "stream" type */ 81var_dump(ucfirst($string1)); 82 83/* $string2 holds a value of "int(0)" */ 84var_dump(ucfirst($string2)); 85 86fclose($file1); // closing the file "dummy.txt" 87unlink("$filename1"); // deletes "dummy.txt" 88 89 90echo "\n--- Testing a longer and heredoc string ---\n"; 91$string = <<<EOD 92abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 93abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 94abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 95abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 96abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 97abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 98abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 99@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 100abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 101EOD; 102var_dump(ucfirst($string)); 103 104echo "\n--- Testing a heredoc null string ---\n"; 105$str = <<<EOD 106EOD; 107var_dump(ucfirst($str)); 108 109 110echo "\n--- Testing simple and complex syntax strings ---\n"; 111$str = 'world'; 112 113/* Simple syntax */ 114var_dump(ucfirst("$str")); 115var_dump(ucfirst("$str'S")); 116var_dump(ucfirst("$strS")); 117 118/* String with curly braces, complex syntax */ 119var_dump(ucfirst("${str}S")); 120var_dump(ucfirst("{$str}S")); 121 122echo "\n--- Nested ucfirst() ---\n"; 123var_dump(ucfirst(ucfirst("hello"))); 124 125 126echo "\n#### error conditions ####"; 127/* Zero arguments */ 128ucfirst(); 129/* More than expected no. of args */ 130ucfirst($str_array[0], $str_array[1]); 131ucfirst((int)10, (int)20); 132 133echo "Done\n"; 134?> 135--EXPECTF-- 136#### Basic and Various operations #### 137 138Warning: Use of undefined constant somestring - assumed 'somestring' (this will throw an Error in a future version of PHP) in %s on line %d 139string(16) "Testing ucfirst." 140string(17) "1.testing ucfirst" 141string(11) "HELLO wORLD" 142string(11) "HELLO wORLD" 143string(1) "" 144string(1) "" 145string(2) "0" 146string(4) "Abcd" 147string(3) "Xyz" 148string(10) "Somestring" 149string(2) "-3" 150string(2) "-3" 151string(6) "-3.344" 152string(6) "-3.344" 153string(0) "" 154string(4) "NULL" 155string(1) "0" 156string(1) "0" 157string(1) "1" 158string(4) "TRUE" 159string(1) "1" 160string(1) "1" 161string(8) "1.234444" 162string(0) "" 163string(5) "FALSE" 164string(1) " " 165string(5) " " 166string(1) "B" 167string(2) "\t" 168string(1) " " 169string(2) "12" 170string(8) "12twelve" 171 172#### Testing Miscelleneous inputs #### 173--- Testing arrays --- 174Warning: ucfirst() expects parameter 1 to be string, array given in %s on line %d 175NULL 176 177--- Testing objects --- 178string(12) "Hello, world" 179 180--- Testing Resources --- 181string(6) "Stream" 182string(1) "0" 183 184--- Testing a longer and heredoc string --- 185string(639) "Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 186abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 187abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 188abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 189abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 190abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 191abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 192@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 193abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789" 194 195--- Testing a heredoc null string --- 196string(0) "" 197 198--- Testing simple and complex syntax strings --- 199string(5) "World" 200string(7) "World'S" 201 202Notice: Undefined variable: strS in %s on line %d 203string(0) "" 204string(6) "WorldS" 205string(6) "WorldS" 206 207--- Nested ucfirst() --- 208string(5) "Hello" 209 210#### error conditions #### 211Warning: ucfirst() expects exactly 1 parameter, 0 given in %s on line %d 212 213Warning: ucfirst() expects exactly 1 parameter, 2 given in %s on line %d 214 215Warning: ucfirst() expects exactly 1 parameter, 2 given in %s on line %d 216Done 217