1--TEST-- 2lcfirst() 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 "-3", 21 -3, 22 '-3.344', 23 -3.344, 24 "NULL", 25 "0", 26 0, 27 TRUE, // bool type 28 "TRUE", 29 "1", 30 1, 31 1.234444, 32 FALSE, 33 "FALSE", 34 " ", 35 " ", 36 'b', // single char 37 '\t', // escape sequences 38 "\t", 39 "12", 40 "12twelve", // int + string 41 ); 42/* loop to test working of lcfirst with different values */ 43foreach ($str_array as $string) { 44 var_dump( lcfirst($string) ); 45} 46 47 48 49echo "\n#### Testing miscellaneous inputs ####\n"; 50 51echo "\n--- Testing lowercamelcase action call example ---\n"; 52class Setter { 53 54 protected $vars = array('partnerName' => false); 55 56 public function __call($m, $v) { 57 if (stristr($m, 'set')) { 58 $action = lcfirst(substr($m, 3)); 59 $this->$action = $v[0]; 60 } 61 } 62 63 public function __set($key, $value) { 64 if (array_key_exists($key, $this->vars)) { 65 $this->vars[$key] = $value; 66 } 67 } 68 69 public function __get($key) { 70 if (array_key_exists($key, $this->vars)) { 71 return $this->vars[$key]; 72 } 73 } 74} 75 76$class = new Setter(); 77$class->setPartnerName('partnerName'); 78var_dump($class->partnerName); 79 80echo "\n--- Testing objects ---\n"; 81/* we get "Recoverable fatal error: saying Object of class could not be converted 82 to string" by default when an object is passed instead of string: 83The error can be avoided by choosing the __toString magix method as follows: */ 84 85class stringObject { 86 function __toString() { 87 return "Hello world"; 88 } 89} 90$obj_string = new stringObject; 91 92var_dump(lcfirst("$obj_string")); 93 94 95echo "\n--- Testing a longer and heredoc string ---\n"; 96$string = <<<EOD 97Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 98abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 99abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 100abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 101abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 102abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 103abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 104@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 105abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 106EOD; 107var_dump(lcfirst($string)); 108 109echo "\n--- Testing a heredoc null string ---\n"; 110$str = <<<EOD 111EOD; 112var_dump(lcfirst($str)); 113 114 115echo "\n--- Testing simple and complex syntax strings ---\n"; 116$str = 'world'; 117 118/* Simple syntax */ 119var_dump(lcfirst("$str")); 120var_dump(lcfirst("$str'S")); 121var_dump(lcfirst("$strS")); 122 123/* String with curly braces, complex syntax */ 124var_dump(lcfirst("${str}S")); 125var_dump(lcfirst("{$str}S")); 126 127echo "\n--- Nested lcfirst() ---\n"; 128var_dump(lcfirst(lcfirst("hello"))); 129 130echo "Done\n"; 131?> 132--EXPECTF-- 133#### Basic and Various operations #### 134string(16) "tesTing lcfirst." 135string(17) "1.testing lcfirst" 136string(11) "hELLO wORLD" 137string(11) "hELLO wORLD" 138string(1) "%0" 139string(1) "%0" 140string(2) "%00" 141string(4) "abcd" 142string(3) "xyz" 143string(2) "-3" 144string(2) "-3" 145string(6) "-3.344" 146string(6) "-3.344" 147string(4) "nULL" 148string(1) "0" 149string(1) "0" 150string(1) "1" 151string(4) "tRUE" 152string(1) "1" 153string(1) "1" 154string(8) "1.234444" 155string(0) "" 156string(5) "fALSE" 157string(1) " " 158string(5) " " 159string(1) "b" 160string(2) "\t" 161string(1) " " 162string(2) "12" 163string(8) "12twelve" 164 165#### Testing miscellaneous inputs #### 166 167--- Testing lowercamelcase action call example --- 168string(%d) "partnerName" 169 170--- Testing objects --- 171string(11) "hello world" 172 173--- Testing a longer and heredoc string --- 174string(639) "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 175abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 176abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 177abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 178abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 179abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 180abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 181@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&* 182abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789" 183 184--- Testing a heredoc null string --- 185string(0) "" 186 187--- Testing simple and complex syntax strings --- 188string(5) "world" 189string(7) "world'S" 190 191Warning: Undefined variable $strS in %s on line %d 192string(0) "" 193string(6) "worldS" 194string(6) "worldS" 195 196--- Nested lcfirst() --- 197string(5) "hello" 198Done 199