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 a longer and heredoc string ---\n";
102$string = <<<EOD
103Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
104abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
105abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
106abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
107abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
108abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
109abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
110@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
111abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
112EOD;
113var_dump(lcfirst($string));
114
115echo "\n--- Testing a heredoc null string ---\n";
116$str = <<<EOD
117EOD;
118var_dump(lcfirst($str));
119
120
121echo "\n--- Testing simple and complex syntax strings ---\n";
122$str = 'world';
123
124/* Simple syntax */
125var_dump(lcfirst("$str"));
126var_dump(lcfirst("$str'S"));
127var_dump(lcfirst("$strS"));
128
129/* String with curly braces, complex syntax */
130var_dump(lcfirst("${str}S"));
131var_dump(lcfirst("{$str}S"));
132
133echo "\n--- Nested lcfirst() ---\n";
134var_dump(lcfirst(lcfirst("hello")));
135
136
137echo "\n#### error conditions ####";
138/* Zero arguments */
139lcfirst();
140/* More than expected no. of args */
141lcfirst($str_array[0], $str_array[1]);
142lcfirst((int)10, (int)20);
143
144echo "Done\n";
145?>
146--EXPECTF--
147#### Basic and Various operations ####
148
149Warning: Use of undefined constant somestring - assumed 'somestring' (this will throw an Error in a future version of PHP) in %s on line %d
150string(16) "tesTing lcfirst."
151string(17) "1.testing lcfirst"
152string(11) "hELLO wORLD"
153string(11) "hELLO wORLD"
154string(1) "�"
155string(1) "�"
156string(2) "�0"
157string(4) "abcd"
158string(3) "xyz"
159string(10) "somestring"
160string(2) "-3"
161string(2) "-3"
162string(6) "-3.344"
163string(6) "-3.344"
164string(0) ""
165string(4) "nULL"
166string(1) "0"
167string(1) "0"
168string(1) "1"
169string(4) "tRUE"
170string(1) "1"
171string(1) "1"
172string(8) "1.234444"
173string(0) ""
174string(5) "fALSE"
175string(1) " "
176string(5) "     "
177string(1) "b"
178string(2) "\t"
179string(1) "	"
180string(2) "12"
181string(8) "12twelve"
182
183#### Testing Miscelleneous inputs ####
184--- Testing arrays ---
185Warning: lcfirst() expects parameter 1 to be string, array given in %s on line %d
186NULL
187
188--- Testing lowercamelcase action call example ---
189string(%d) "partnerName"
190
191--- Testing objects ---
192string(11) "hello world"
193
194--- Testing a longer and heredoc string ---
195string(639) "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
196abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
197abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
198abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
199abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
200abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
201abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
202@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
203abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
204
205--- Testing a heredoc null string ---
206string(0) ""
207
208--- Testing simple and complex syntax strings ---
209string(5) "world"
210string(7) "world'S"
211
212Notice: Undefined variable: strS in %s on line %d
213string(0) ""
214string(6) "worldS"
215string(6) "worldS"
216
217--- Nested lcfirst() ---
218string(5) "hello"
219
220#### error conditions ####
221Warning: lcfirst() expects exactly 1 parameter, 0 given in %s on line %d
222
223Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d
224
225Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d
226Done
227