Annotation of embedaddon/php/ext/standard/tests/strings/ucfirst.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: "ucfirst()" function
3: --INI--
4: precision=14
5: --FILE--
6: <?php
7: /* Make a string's first character uppercase */
8:
9: echo "#### 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: string, // 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 */
45: foreach ($str_array as $string) {
46: var_dump( ucfirst($string) );
47: }
48:
49:
50:
51: echo "\n#### Testing Miscelleneous inputs ####\n";
52:
53: echo "--- Testing arrays ---";
54: $str_arr = array("hello", "?world", "!$%**()%**[][[[&@#~!", array());
55: var_dump( ucfirst($str_arr) );
56:
57: echo "\n--- Testing objects ---\n";
58: /* we get "Catchable fatal error: saying Object of class could not be converted
59: to string" by default when an object is passed instead of string:
60: The error can be avoided by chosing the __toString magix method as follows: */
61:
62: class string {
63: function __toString() {
64: return "hello, world";
65: }
66: }
67: $obj_string = new string;
68:
69: var_dump(ucfirst("$obj_string"));
70:
71:
72: echo "\n--- Testing Resources ---\n";
73: $filename1 = "dummy.txt";
74: $file1 = fopen($filename1, "w"); // creating new file
75:
76: /* getting resource type for file handle */
77: $string1 = get_resource_type($file1);
78: $string2 = (int)get_resource_type($file1); // converting stream type to int
79:
80: /* $string1 is of "stream" type */
81: var_dump(ucfirst($string1));
82:
83: /* $string2 holds a value of "int(0)" */
84: var_dump(ucfirst($string2));
85:
86: fclose($file1); // closing the file "dummy.txt"
87: unlink("$filename1"); // deletes "dummy.txt"
88:
89:
90: echo "\n--- Testing a longer and heredoc string ---\n";
91: $string = <<<EOD
92: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
93: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
94: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
95: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
96: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
97: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
98: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
99: @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
100: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
101: EOD;
102: var_dump(ucfirst($string));
103:
104: echo "\n--- Testing a heredoc null string ---\n";
105: $str = <<<EOD
106: EOD;
107: var_dump(ucfirst($str));
108:
109:
110: echo "\n--- Testing simple and complex syntax strings ---\n";
111: $str = 'world';
112:
113: /* Simple syntax */
114: var_dump(ucfirst("$str"));
115: var_dump(ucfirst("$str'S"));
116: var_dump(ucfirst("$strS"));
117:
118: /* String with curly braces, complex syntax */
119: var_dump(ucfirst("${str}S"));
120: var_dump(ucfirst("{$str}S"));
121:
122: echo "\n--- Nested ucfirst() ---\n";
123: var_dump(ucfirst(ucfirst("hello")));
124:
125:
126: echo "\n#### error conditions ####";
127: /* Zero arguments */
128: ucfirst();
129: /* More than expected no. of args */
130: ucfirst($str_array[0], $str_array[1]);
131: ucfirst((int)10, (int)20);
132:
133: echo "Done\n";
134: ?>
135: --EXPECTF--
136: #### Basic and Various operations ####
137:
138: Notice: Use of undefined constant string - assumed 'string' in %s on line %d
139: string(16) "Testing ucfirst."
140: string(17) "1.testing ucfirst"
141: string(11) "HELLO wORLD"
142: string(11) "HELLO wORLD"
143: string(1) "