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--
104Deprecated: Using ${var} in strings is deprecated, use {$var} instead in %s on line %d
105#### Basic and Various operations ####
106string(16) "Testing ucfirst."
107string(17) "1.testing ucfirst"
108string(11) "HELLO wORLD"
109string(11) "HELLO wORLD"
110string(1) "%0"
111string(1) "%0"
112string(2) "%00"
113string(4) "Abcd"
114string(3) "Xyz"
115string(2) "-3"
116string(2) "-3"
117string(6) "-3.344"
118string(6) "-3.344"
119string(4) "NULL"
120string(1) "0"
121string(1) "0"
122string(1) "1"
123string(4) "TRUE"
124string(1) "1"
125string(1) "1"
126string(8) "1.234444"
127string(0) ""
128string(5) "FALSE"
129string(1) " "
130string(5) "     "
131string(1) "B"
132string(2) "\t"
133string(1) "	"
134string(2) "12"
135string(8) "12twelve"
136
137#### Testing miscellaneous inputs ####
138
139--- Testing objects ---
140string(12) "Hello, world"
141
142--- Testing a longer and heredoc string ---
143string(639) "Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
144abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
145abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
146abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
147abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
148abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
149abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
150@#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
151abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
152
153--- Testing a heredoc null string ---
154string(0) ""
155
156--- Testing simple and complex syntax strings ---
157string(5) "World"
158string(7) "World'S"
159
160Warning: Undefined variable $strS in %s on line %d
161string(0) ""
162string(6) "WorldS"
163string(6) "WorldS"
164
165--- Nested ucfirst() ---
166string(5) "Hello"
167Done
168