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