ucfirst.phpt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. --TEST--
  2. "ucfirst()" function
  3. --INI--
  4. precision=14
  5. --FILE--
  6. <?php
  7. /* Make a string's first character uppercase */
  8. echo "#### Basic and Various operations ####\n";
  9. $str_array = array(
  10. "testing ucfirst.",
  11. "1.testing ucfirst",
  12. "hELLO wORLD",
  13. 'hELLO wORLD',
  14. "\0", // Null
  15. "\x00", // Hex Null
  16. "\x000",
  17. "abcd", // double quoted string
  18. 'xyz', // single quoted string
  19. "-3",
  20. -3,
  21. '-3.344',
  22. -3.344,
  23. "NULL",
  24. "0",
  25. 0,
  26. TRUE, // bool type
  27. "TRUE",
  28. "1",
  29. 1,
  30. 1.234444,
  31. FALSE,
  32. "FALSE",
  33. " ",
  34. " ",
  35. 'b', // single char
  36. '\t', // escape sequences
  37. "\t",
  38. "12",
  39. "12twelve", // int + string
  40. );
  41. /* loop to test working of ucfirst with different values */
  42. foreach ($str_array as $string) {
  43. var_dump( ucfirst($string) );
  44. }
  45. echo "\n#### Testing miscellaneous inputs ####\n";
  46. echo "\n--- Testing objects ---\n";
  47. /* we get "Recoverable 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 StringCapable {
  51. function __toString() {
  52. return "hello, world";
  53. }
  54. }
  55. $obj_string = new StringCapable;
  56. var_dump(ucfirst("$obj_string"));
  57. echo "\n--- Testing a longer and heredoc string ---\n";
  58. $string = <<<EOD
  59. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  60. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  61. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  62. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  63. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  64. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  65. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  66. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  67. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  68. EOD;
  69. var_dump(ucfirst($string));
  70. echo "\n--- Testing a heredoc null string ---\n";
  71. $str = <<<EOD
  72. EOD;
  73. var_dump(ucfirst($str));
  74. echo "\n--- Testing simple and complex syntax strings ---\n";
  75. $str = 'world';
  76. /* Simple syntax */
  77. var_dump(ucfirst("$str"));
  78. var_dump(ucfirst("$str'S"));
  79. var_dump(ucfirst("$strS"));
  80. /* String with curly braces, complex syntax */
  81. var_dump(ucfirst("${str}S"));
  82. var_dump(ucfirst("{$str}S"));
  83. echo "\n--- Nested ucfirst() ---\n";
  84. var_dump(ucfirst(ucfirst("hello")));
  85. echo "Done\n";
  86. ?>
  87. --EXPECTF--
  88. #### Basic and Various operations ####
  89. string(16) "Testing ucfirst."
  90. string(17) "1.testing ucfirst"
  91. string(11) "HELLO wORLD"
  92. string(11) "HELLO wORLD"
  93. string(1) "%0"
  94. string(1) "%0"
  95. string(2) "%00"
  96. string(4) "Abcd"
  97. string(3) "Xyz"
  98. string(2) "-3"
  99. string(2) "-3"
  100. string(6) "-3.344"
  101. string(6) "-3.344"
  102. string(4) "NULL"
  103. string(1) "0"
  104. string(1) "0"
  105. string(1) "1"
  106. string(4) "TRUE"
  107. string(1) "1"
  108. string(1) "1"
  109. string(8) "1.234444"
  110. string(0) ""
  111. string(5) "FALSE"
  112. string(1) " "
  113. string(5) " "
  114. string(1) "B"
  115. string(2) "\t"
  116. string(1) " "
  117. string(2) "12"
  118. string(8) "12twelve"
  119. #### Testing miscellaneous inputs ####
  120. --- Testing objects ---
  121. string(12) "Hello, world"
  122. --- Testing a longer and heredoc string ---
  123. string(639) "Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  124. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  125. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  126. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  127. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  128. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  129. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  130. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  131. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
  132. --- Testing a heredoc null string ---
  133. string(0) ""
  134. --- Testing simple and complex syntax strings ---
  135. string(5) "World"
  136. string(7) "World'S"
  137. Warning: Undefined variable $strS in %s on line %d
  138. string(0) ""
  139. string(6) "WorldS"
  140. string(6) "WorldS"
  141. --- Nested ucfirst() ---
  142. string(5) "Hello"
  143. Done