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                    "-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 ucfirst with different values */
43foreach ($str_array as $string) {
44  var_dump( ucfirst($string) );
45}
46
47
48
49echo "\n#### Testing miscellaneous inputs ####\n";
50
51echo "\n--- Testing objects ---\n";
52/* we get "Recoverable fatal error: saying Object of class could not be converted
53        to string" by default when an object is passed instead of string:
54The error can be  avoided by choosing the __toString magix method as follows: */
55
56class StringCapable {
57  function __toString() {
58    return "hello, world";
59  }
60}
61$obj_string = new StringCapable;
62
63var_dump(ucfirst("$obj_string"));
64
65
66echo "\n--- Testing a longer and heredoc string ---\n";
67$string = <<<EOD
68abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
69abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
70abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
71abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
72abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
73abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
74abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
75@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
76abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
77EOD;
78var_dump(ucfirst($string));
79
80echo "\n--- Testing a heredoc null string ---\n";
81$str = <<<EOD
82EOD;
83var_dump(ucfirst($str));
84
85
86echo "\n--- Testing simple and complex syntax strings ---\n";
87$str = 'world';
88
89/* Simple syntax */
90var_dump(ucfirst("$str"));
91var_dump(ucfirst("$str'S"));
92var_dump(ucfirst("$strS"));
93
94/* String with curly braces, complex syntax */
95var_dump(ucfirst("${str}S"));
96var_dump(ucfirst("{$str}S"));
97
98echo "\n--- Nested ucfirst() ---\n";
99var_dump(ucfirst(ucfirst("hello")));
100
101echo "Done\n";
102?>
103--EXPECTF--
104#### Basic and Various operations ####
105string(16) "Testing ucfirst."
106string(17) "1.testing ucfirst"
107string(11) "HELLO wORLD"
108string(11) "HELLO wORLD"
109string(1) "%0"
110string(1) "%0"
111string(2) "%00"
112string(4) "Abcd"
113string(3) "Xyz"
114string(2) "-3"
115string(2) "-3"
116string(6) "-3.344"
117string(6) "-3.344"
118string(4) "NULL"
119string(1) "0"
120string(1) "0"
121string(1) "1"
122string(4) "TRUE"
123string(1) "1"
124string(1) "1"
125string(8) "1.234444"
126string(0) ""
127string(5) "FALSE"
128string(1) " "
129string(5) "     "
130string(1) "B"
131string(2) "\t"
132string(1) "	"
133string(2) "12"
134string(8) "12twelve"
135
136#### Testing miscellaneous inputs ####
137
138--- Testing objects ---
139string(12) "Hello, world"
140
141--- Testing a longer and heredoc string ---
142string(639) "Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
143abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
144abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
145abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
146abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
147abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
148abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
149@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
150abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
151
152--- Testing a heredoc null string ---
153string(0) ""
154
155--- Testing simple and complex syntax strings ---
156string(5) "World"
157string(7) "World'S"
158
159Warning: Undefined variable $strS in %s on line %d
160string(0) ""
161string(6) "WorldS"
162string(6) "WorldS"
163
164--- Nested ucfirst() ---
165string(5) "Hello"
166Done
167