PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/hphp/test/zend/bad/ext/standard/tests/strings/ucfirst.php

http://github.com/facebook/hiphop-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
  1. <?php
  2. /* Make a string's first character uppercase */
  3. echo "#### Basic and Various operations ####\n";
  4. $str_array = array(
  5. "testing ucfirst.",
  6. "1.testing ucfirst",
  7. "hELLO wORLD",
  8. 'hELLO wORLD',
  9. "\0", // Null
  10. "\x00", // Hex Null
  11. "\x000",
  12. "abcd", // double quoted string
  13. 'xyz', // single quoted string
  14. string, // without quotes
  15. "-3",
  16. -3,
  17. '-3.344',
  18. -3.344,
  19. NULL,
  20. "NULL",
  21. "0",
  22. 0,
  23. TRUE, // bool type
  24. "TRUE",
  25. "1",
  26. 1,
  27. 1.234444,
  28. FALSE,
  29. "FALSE",
  30. " ",
  31. " ",
  32. 'b', // single char
  33. '\t', // escape sequences
  34. "\t",
  35. "12",
  36. "12twelve", // int + string
  37. );
  38. /* loop to test working of ucfirst with different values */
  39. foreach ($str_array as $string) {
  40. var_dump( ucfirst($string) );
  41. }
  42. echo "\n#### Testing Miscelleneous inputs ####\n";
  43. echo "--- Testing arrays ---";
  44. $str_arr = array("hello", "?world", "!$%**()%**[][[[&@#~!", array());
  45. var_dump( ucfirst($str_arr) );
  46. echo "\n--- Testing objects ---\n";
  47. /* we get "Catchable fatal error: saying Object of class could not be converted
  48. to string" by default when an object is passed instead of string:
  49. The error can be avoided by choosing the __toString magix method as follows: */
  50. class string {
  51. function __toString() {
  52. return "hello, world";
  53. }
  54. }
  55. $obj_string = new string;
  56. var_dump(ucfirst("$obj_string"));
  57. echo "\n--- Testing Resources ---\n";
  58. $filename1 = "dummy.txt";
  59. $file1 = fopen($filename1, "w"); // creating new file
  60. /* getting resource type for file handle */
  61. $string1 = get_resource_type($file1);
  62. $string2 = (int)get_resource_type($file1); // converting stream type to int
  63. /* $string1 is of "stream" type */
  64. var_dump(ucfirst($string1));
  65. /* $string2 holds a value of "int(0)" */
  66. var_dump(ucfirst($string2));
  67. fclose($file1); // closing the file "dummy.txt"
  68. unlink("$filename1"); // deletes "dummy.txt"
  69. echo "\n--- Testing a longer and heredoc string ---\n";
  70. $string = <<<EOD
  71. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  72. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  73. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  74. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  75. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  76. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  77. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  78. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  79. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  80. EOD;
  81. var_dump(ucfirst($string));
  82. echo "\n--- Testing a heredoc null string ---\n";
  83. $str = <<<EOD
  84. EOD;
  85. var_dump(ucfirst($str));
  86. echo "\n--- Testing simple and complex syntax strings ---\n";
  87. $str = 'world';
  88. /* Simple syntax */
  89. var_dump(ucfirst("$str"));
  90. var_dump(ucfirst("$str'S"));
  91. var_dump(ucfirst("$strS"));
  92. /* String with curly braces, complex syntax */
  93. var_dump(ucfirst("${str}S"));
  94. var_dump(ucfirst("{$str}S"));
  95. echo "\n--- Nested ucfirst() ---\n";
  96. var_dump(ucfirst(ucfirst("hello")));
  97. echo "\n#### error conditions ####";
  98. /* Zero arguments */
  99. ucfirst();
  100. /* More than expected no. of args */
  101. ucfirst($str_array[0], $str_array[1]);
  102. ucfirst((int)10, (int)20);
  103. echo "Done\n";
  104. ?>