/hphp/test/zend/bad/ext/standard/tests/strings/ucfirst.php
PHP | 129 lines | 100 code | 20 blank | 9 comment | 0 complexity | 0a9f218e5177c690aef80cbdb679d3e8 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- <?php
- /* Make a string's first character uppercase */
- echo "#### Basic and Various operations ####\n";
- $str_array = array(
- "testing ucfirst.",
- "1.testing ucfirst",
- "hELLO wORLD",
- 'hELLO wORLD',
- "\0", // Null
- "\x00", // Hex Null
- "\x000",
- "abcd", // double quoted string
- 'xyz', // single quoted string
- string, // without quotes
- "-3",
- -3,
- '-3.344',
- -3.344,
- NULL,
- "NULL",
- "0",
- 0,
- TRUE, // bool type
- "TRUE",
- "1",
- 1,
- 1.234444,
- FALSE,
- "FALSE",
- " ",
- " ",
- 'b', // single char
- '\t', // escape sequences
- "\t",
- "12",
- "12twelve", // int + string
- );
- /* loop to test working of ucfirst with different values */
- foreach ($str_array as $string) {
- var_dump( ucfirst($string) );
- }
- echo "\n#### Testing Miscelleneous inputs ####\n";
- echo "--- Testing arrays ---";
- $str_arr = array("hello", "?world", "!$%**()%**[][[[&@#~!", array());
- var_dump( ucfirst($str_arr) );
- echo "\n--- Testing objects ---\n";
- /* we get "Catchable fatal error: saying Object of class could not be converted
- to string" by default when an object is passed instead of string:
- The error can be avoided by choosing the __toString magix method as follows: */
- class string {
- function __toString() {
- return "hello, world";
- }
- }
- $obj_string = new string;
- var_dump(ucfirst("$obj_string"));
- echo "\n--- Testing Resources ---\n";
- $filename1 = "dummy.txt";
- $file1 = fopen($filename1, "w"); // creating new file
- /* getting resource type for file handle */
- $string1 = get_resource_type($file1);
- $string2 = (int)get_resource_type($file1); // converting stream type to int
- /* $string1 is of "stream" type */
- var_dump(ucfirst($string1));
- /* $string2 holds a value of "int(0)" */
- var_dump(ucfirst($string2));
- fclose($file1); // closing the file "dummy.txt"
- unlink("$filename1"); // deletes "dummy.txt"
- echo "\n--- Testing a longer and heredoc string ---\n";
- $string = <<<EOD
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
- abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
- EOD;
- var_dump(ucfirst($string));
- echo "\n--- Testing a heredoc null string ---\n";
- $str = <<<EOD
- EOD;
- var_dump(ucfirst($str));
- echo "\n--- Testing simple and complex syntax strings ---\n";
- $str = 'world';
- /* Simple syntax */
- var_dump(ucfirst("$str"));
- var_dump(ucfirst("$str'S"));
- var_dump(ucfirst("$strS"));
- /* String with curly braces, complex syntax */
- var_dump(ucfirst("${str}S"));
- var_dump(ucfirst("{$str}S"));
- echo "\n--- Nested ucfirst() ---\n";
- var_dump(ucfirst(ucfirst("hello")));
- echo "\n#### error conditions ####";
- /* Zero arguments */
- ucfirst();
- /* More than expected no. of args */
- ucfirst($str_array[0], $str_array[1]);
- ucfirst((int)10, (int)20);
- echo "Done\n";
- ?>