1--TEST--
2"ucfirst()" 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 ucfirst.",
12 		    "1.testing ucfirst",
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 ucfirst with different values */
45foreach ($str_array as $string) {
46  var_dump( ucfirst($string) );
47}
48
49
50
51echo "\n#### Testing Miscelleneous inputs ####\n";
52
53echo "--- Testing arrays ---";
54$str_arr = array("hello", "?world", "!$%**()%**[][[[&@#~!", array());
55var_dump( ucfirst($str_arr) );
56
57echo "\n--- Testing objects ---\n";
58/* we get "Recoverable fatal error: saying Object of class could not be converted
59        to string" by default when an object is passed instead of string:
60The error can be  avoided by choosing the __toString magix method as follows: */
61
62class stringable {
63  function __toString() {
64    return "hello, world";
65  }
66}
67$obj_string = new stringable;
68
69var_dump(ucfirst("$obj_string"));
70
71
72echo "\n--- Testing a longer and heredoc string ---\n";
73$string = <<<EOD
74abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
75abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
76abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
77abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
78abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
79abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
80abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
81@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
82abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
83EOD;
84var_dump(ucfirst($string));
85
86echo "\n--- Testing a heredoc null string ---\n";
87$str = <<<EOD
88EOD;
89var_dump(ucfirst($str));
90
91
92echo "\n--- Testing simple and complex syntax strings ---\n";
93$str = 'world';
94
95/* Simple syntax */
96var_dump(ucfirst("$str"));
97var_dump(ucfirst("$str'S"));
98var_dump(ucfirst("$strS"));
99
100/* String with curly braces, complex syntax */
101var_dump(ucfirst("${str}S"));
102var_dump(ucfirst("{$str}S"));
103
104echo "\n--- Nested ucfirst() ---\n";
105var_dump(ucfirst(ucfirst("hello")));
106
107
108echo "\n#### error conditions ####";
109/* Zero arguments */
110ucfirst();
111/* More than expected no. of args */
112ucfirst($str_array[0], $str_array[1]);
113ucfirst((int)10, (int)20);
114
115echo "Done\n";
116?>
117--EXPECTF--
118#### Basic and Various operations ####
119
120Warning: Use of undefined constant somestring - assumed 'somestring' (this will throw an Error in a future version of PHP) in %s on line %d
121string(16) "Testing ucfirst."
122string(17) "1.testing ucfirst"
123string(11) "HELLO wORLD"
124string(11) "HELLO wORLD"
125string(1) "�"
126string(1) "�"
127string(2) "�0"
128string(4) "Abcd"
129string(3) "Xyz"
130string(10) "Somestring"
131string(2) "-3"
132string(2) "-3"
133string(6) "-3.344"
134string(6) "-3.344"
135string(0) ""
136string(4) "NULL"
137string(1) "0"
138string(1) "0"
139string(1) "1"
140string(4) "TRUE"
141string(1) "1"
142string(1) "1"
143string(8) "1.234444"
144string(0) ""
145string(5) "FALSE"
146string(1) " "
147string(5) "     "
148string(1) "B"
149string(2) "\t"
150string(1) "	"
151string(2) "12"
152string(8) "12twelve"
153
154#### Testing Miscelleneous inputs ####
155--- Testing arrays ---
156Warning: ucfirst() expects parameter 1 to be string, array given in %s on line %d
157NULL
158
159--- Testing objects ---
160string(12) "Hello, world"
161
162--- Testing a longer and heredoc string ---
163string(639) "Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
164abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
165abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
166abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
167abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
168abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
169abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
170@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
171abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
172
173--- Testing a heredoc null string ---
174string(0) ""
175
176--- Testing simple and complex syntax strings ---
177string(5) "World"
178string(7) "World'S"
179
180Notice: Undefined variable: strS in %s on line %d
181string(0) ""
182string(6) "WorldS"
183string(6) "WorldS"
184
185--- Nested ucfirst() ---
186string(5) "Hello"
187
188#### error conditions ####
189Warning: ucfirst() expects exactly 1 parameter, 0 given in %s on line %d
190
191Warning: ucfirst() expects exactly 1 parameter, 2 given in %s on line %d
192
193Warning: ucfirst() expects exactly 1 parameter, 2 given in %s on line %d
194Done
195