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--
133Deprecated: Using ${var} in strings is deprecated, use {$var} instead in %s on line %d
134#### Basic and Various operations ####
135string(16) "tesTing lcfirst."
136string(17) "1.testing lcfirst"
137string(11) "hELLO wORLD"
138string(11) "hELLO wORLD"
139string(1) "%0"
140string(1) "%0"
141string(2) "%00"
142string(4) "abcd"
143string(3) "xyz"
144string(2) "-3"
145string(2) "-3"
146string(6) "-3.344"
147string(6) "-3.344"
148string(4) "nULL"
149string(1) "0"
150string(1) "0"
151string(1) "1"
152string(4) "tRUE"
153string(1) "1"
154string(1) "1"
155string(8) "1.234444"
156string(0) ""
157string(5) "fALSE"
158string(1) " "
159string(5) "     "
160string(1) "b"
161string(2) "\t"
162string(1) "	"
163string(2) "12"
164string(8) "12twelve"
165
166#### Testing miscellaneous inputs ####
167
168--- Testing lowercamelcase action call example ---
169string(%d) "partnerName"
170
171--- Testing objects ---
172string(11) "hello world"
173
174--- Testing a longer and heredoc string ---
175string(639) "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
176abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
177abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
178abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
179abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
180abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
181abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
182@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
183abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
184
185--- Testing a heredoc null string ---
186string(0) ""
187
188--- Testing simple and complex syntax strings ---
189string(5) "world"
190string(7) "world'S"
191
192Warning: Undefined variable $strS in %s on line %d
193string(0) ""
194string(6) "worldS"
195string(6) "worldS"
196
197--- Nested lcfirst() ---
198string(5) "hello"
199Done
200