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