1--TEST-- 2"lcfirst()" 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 lcfirst.", 12 "1.testing lcfirst", 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 lcfirst with different values */ 45foreach ($str_array as $string) { 46 var_dump( lcfirst($string) ); 47} 48 49 50 51echo "\n#### Testing Miscelleneous inputs ####\n"; 52 53echo "--- Testing arrays ---"; 54$str_arr = array("Hello", "?world", "!$%**()%**[][[[&@#~!", array()); 55var_dump( lcfirst($str_arr) ); 56 57echo "\n--- Testing lowercamelcase action call example ---\n"; 58class Setter { 59 60 protected $vars = array('partnerName' => false); 61 62 public function __call($m, $v) { 63 if (stristr($m, 'set')) { 64 $action = lcfirst(substr($m, 3)); 65 $this->$action = $v[0]; 66 } 67 } 68 69 public function __set($key, $value) { 70 if (array_key_exists($key, $this->vars)) { 71 $this->vars[$key] = $value; 72 } 73 } 74 75 public function __get($key) { 76 if (array_key_exists($key, $this->vars)) { 77 return $this->vars[$key]; 78 } 79 } 80} 81 82$class = new Setter(); 83$class->setPartnerName('partnerName'); 84var_dump($class->partnerName); 85 86echo "\n--- Testing objects ---\n"; 87/* we get "Recoverable fatal error: saying Object of class could not be converted 88 to string" by default when an object is passed instead of string: 89The error can be avoided by choosing the __toString magix method as follows: */ 90 91class stringObject { 92 function __toString() { 93 return "Hello world"; 94 } 95} 96$obj_string = new stringObject; 97 98var_dump(lcfirst("$obj_string")); 99 100 101echo "\n--- Testing Resources ---\n"; 102$filename1 = "dummy.txt"; 103$file1 = fopen($filename1, "w"); // creating new file 104 105/* getting resource type for file handle */ 106$string1 = get_resource_type($file1); 107$string2 = (int)get_resource_type($file1); // converting stream type to int 108 109/* $string1 is of "stream" type */ 110var_dump(lcfirst($string1)); 111 112/* $string2 holds a value of "int(0)" */ 113var_dump(lcfirst($string2)); 114 115fclose($file1); // closing the file "dummy.txt" 116unlink("$filename1"); // deletes "dummy.txt" 117 118 119echo "\n--- Testing a longer and heredoc string ---\n"; 120$string = <<<EOD 121Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 122abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 123abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 124abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 125abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 126abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 127abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 128@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 129abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 130EOD; 131var_dump(lcfirst($string)); 132 133echo "\n--- Testing a heredoc null string ---\n"; 134$str = <<<EOD 135EOD; 136var_dump(lcfirst($str)); 137 138 139echo "\n--- Testing simple and complex syntax strings ---\n"; 140$str = 'world'; 141 142/* Simple syntax */ 143var_dump(lcfirst("$str")); 144var_dump(lcfirst("$str'S")); 145var_dump(lcfirst("$strS")); 146 147/* String with curly braces, complex syntax */ 148var_dump(lcfirst("${str}S")); 149var_dump(lcfirst("{$str}S")); 150 151echo "\n--- Nested lcfirst() ---\n"; 152var_dump(lcfirst(lcfirst("hello"))); 153 154 155echo "\n#### error conditions ####"; 156/* Zero arguments */ 157lcfirst(); 158/* More than expected no. of args */ 159lcfirst($str_array[0], $str_array[1]); 160lcfirst((int)10, (int)20); 161 162echo "Done\n"; 163?> 164--EXPECTF-- 165#### Basic and Various operations #### 166 167Warning: Use of undefined constant somestring - assumed 'somestring' (this will throw an Error in a future version of PHP) in %s on line %d 168string(16) "tesTing lcfirst." 169string(17) "1.testing lcfirst" 170string(11) "hELLO wORLD" 171string(11) "hELLO wORLD" 172string(1) "" 173string(1) "" 174string(2) "0" 175string(4) "abcd" 176string(3) "xyz" 177string(10) "somestring" 178string(2) "-3" 179string(2) "-3" 180string(6) "-3.344" 181string(6) "-3.344" 182string(0) "" 183string(4) "nULL" 184string(1) "0" 185string(1) "0" 186string(1) "1" 187string(4) "tRUE" 188string(1) "1" 189string(1) "1" 190string(8) "1.234444" 191string(0) "" 192string(5) "fALSE" 193string(1) " " 194string(5) " " 195string(1) "b" 196string(2) "\t" 197string(1) " " 198string(2) "12" 199string(8) "12twelve" 200 201#### Testing Miscelleneous inputs #### 202--- Testing arrays --- 203Warning: lcfirst() expects parameter 1 to be string, array given in %s on line %d 204NULL 205 206--- Testing lowercamelcase action call example --- 207string(%d) "partnerName" 208 209--- Testing objects --- 210string(11) "hello world" 211 212--- Testing Resources --- 213string(6) "stream" 214string(1) "0" 215 216--- Testing a longer and heredoc string --- 217string(639) "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 218abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 219abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 220abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 221abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 222abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 223abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 224@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 225abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789" 226 227--- Testing a heredoc null string --- 228string(0) "" 229 230--- Testing simple and complex syntax strings --- 231string(5) "world" 232string(7) "world'S" 233 234Notice: Undefined variable: strS in %s on line %d 235string(0) "" 236string(6) "worldS" 237string(6) "worldS" 238 239--- Nested lcfirst() --- 240string(5) "hello" 241 242#### error conditions #### 243Warning: lcfirst() expects exactly 1 parameter, 0 given in %s on line %d 244 245Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d 246 247Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d 248Done 249