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 "-3", 21 -3, 22 '-3.344', 23 -3.344, 24 NULL, 25 "NULL", 26 "0", 27 0, 28 TRUE, // bool type 29 "TRUE", 30 "1", 31 1, 32 1.234444, 33 FALSE, 34 "FALSE", 35 " ", 36 " ", 37 'b', // single char 38 '\t', // escape sequences 39 "\t", 40 "12", 41 "12twelve", // int + string 42 ); 43/* loop to test working of ucfirst with different values */ 44foreach ($str_array as $string) { 45 var_dump( ucfirst($string) ); 46} 47 48 49 50echo "\n#### Testing miscellaneous inputs ####\n"; 51 52echo "\n--- Testing objects ---\n"; 53/* we get "Recoverable fatal error: saying Object of class could not be converted 54 to string" by default when an object is passed instead of string: 55The error can be avoided by choosing the __toString magix method as follows: */ 56 57class StringCapable { 58 function __toString() { 59 return "hello, world"; 60 } 61} 62$obj_string = new StringCapable; 63 64var_dump(ucfirst("$obj_string")); 65 66 67echo "\n--- Testing a longer and heredoc string ---\n"; 68$string = <<<EOD 69abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 70abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 71abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 72abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 73abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 74abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 75abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 76@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 77abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 78EOD; 79var_dump(ucfirst($string)); 80 81echo "\n--- Testing a heredoc null string ---\n"; 82$str = <<<EOD 83EOD; 84var_dump(ucfirst($str)); 85 86 87echo "\n--- Testing simple and complex syntax strings ---\n"; 88$str = 'world'; 89 90/* Simple syntax */ 91var_dump(ucfirst("$str")); 92var_dump(ucfirst("$str'S")); 93var_dump(ucfirst("$strS")); 94 95/* String with curly braces, complex syntax */ 96var_dump(ucfirst("${str}S")); 97var_dump(ucfirst("{$str}S")); 98 99echo "\n--- Nested ucfirst() ---\n"; 100var_dump(ucfirst(ucfirst("hello"))); 101 102echo "Done\n"; 103?> 104--EXPECTF-- 105#### Basic and Various operations #### 106string(16) "Testing ucfirst." 107string(17) "1.testing ucfirst" 108string(11) "HELLO wORLD" 109string(11) "HELLO wORLD" 110string(1) "" 111string(1) "" 112string(2) "0" 113string(4) "Abcd" 114string(3) "Xyz" 115string(2) "-3" 116string(2) "-3" 117string(6) "-3.344" 118string(6) "-3.344" 119string(0) "" 120string(4) "NULL" 121string(1) "0" 122string(1) "0" 123string(1) "1" 124string(4) "TRUE" 125string(1) "1" 126string(1) "1" 127string(8) "1.234444" 128string(0) "" 129string(5) "FALSE" 130string(1) " " 131string(5) " " 132string(1) "B" 133string(2) "\t" 134string(1) " " 135string(2) "12" 136string(8) "12twelve" 137 138#### Testing miscellaneous inputs #### 139 140--- Testing objects --- 141string(12) "Hello, world" 142 143--- Testing a longer and heredoc string --- 144string(639) "Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 145abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 146abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 147abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 148abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 149abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 150abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 151@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 152abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789" 153 154--- Testing a heredoc null string --- 155string(0) "" 156 157--- Testing simple and complex syntax strings --- 158string(5) "World" 159string(7) "World'S" 160 161Warning: Undefined variable $strS in %s on line %d 162string(0) "" 163string(6) "WorldS" 164string(6) "WorldS" 165 166--- Nested ucfirst() --- 167string(5) "Hello" 168Done 169