lcfirst.phpt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. --TEST--
  2. lcfirst() 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 lcfirst.",
  11. "1.testing lcfirst",
  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 lcfirst with different values */
  42. foreach ($str_array as $string) {
  43. var_dump( lcfirst($string) );
  44. }
  45. echo "\n#### Testing miscellaneous inputs ####\n";
  46. echo "\n--- Testing lowercamelcase action call example ---\n";
  47. class Setter {
  48. protected $vars = array('partnerName' => false);
  49. public function __call($m, $v) {
  50. if (stristr($m, 'set')) {
  51. $action = lcfirst(substr($m, 3));
  52. $this->$action = $v[0];
  53. }
  54. }
  55. public function __set($key, $value) {
  56. if (array_key_exists($key, $this->vars)) {
  57. $this->vars[$key] = $value;
  58. }
  59. }
  60. public function __get($key) {
  61. if (array_key_exists($key, $this->vars)) {
  62. return $this->vars[$key];
  63. }
  64. }
  65. }
  66. $class = new Setter();
  67. $class->setPartnerName('partnerName');
  68. var_dump($class->partnerName);
  69. echo "\n--- Testing objects ---\n";
  70. /* we get "Recoverable fatal error: saying Object of class could not be converted
  71. to string" by default when an object is passed instead of string:
  72. The error can be avoided by choosing the __toString magix method as follows: */
  73. class stringObject {
  74. function __toString() {
  75. return "Hello world";
  76. }
  77. }
  78. $obj_string = new stringObject;
  79. var_dump(lcfirst("$obj_string"));
  80. echo "\n--- Testing a longer and heredoc string ---\n";
  81. $string = <<<EOD
  82. Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  83. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  84. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  85. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  86. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  87. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  88. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  89. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  90. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  91. EOD;
  92. var_dump(lcfirst($string));
  93. echo "\n--- Testing a heredoc null string ---\n";
  94. $str = <<<EOD
  95. EOD;
  96. var_dump(lcfirst($str));
  97. echo "\n--- Testing simple and complex syntax strings ---\n";
  98. $str = 'world';
  99. /* Simple syntax */
  100. var_dump(lcfirst("$str"));
  101. var_dump(lcfirst("$str'S"));
  102. var_dump(lcfirst("$strS"));
  103. /* String with curly braces, complex syntax */
  104. var_dump(lcfirst("${str}S"));
  105. var_dump(lcfirst("{$str}S"));
  106. echo "\n--- Nested lcfirst() ---\n";
  107. var_dump(lcfirst(lcfirst("hello")));
  108. echo "Done\n";
  109. ?>
  110. --EXPECTF--
  111. #### Basic and Various operations ####
  112. string(16) "tesTing lcfirst."
  113. string(17) "1.testing lcfirst"
  114. string(11) "hELLO wORLD"
  115. string(11) "hELLO wORLD"
  116. string(1) "%0"
  117. string(1) "%0"
  118. string(2) "%00"
  119. string(4) "abcd"
  120. string(3) "xyz"
  121. string(2) "-3"
  122. string(2) "-3"
  123. string(6) "-3.344"
  124. string(6) "-3.344"
  125. string(4) "nULL"
  126. string(1) "0"
  127. string(1) "0"
  128. string(1) "1"
  129. string(4) "tRUE"
  130. string(1) "1"
  131. string(1) "1"
  132. string(8) "1.234444"
  133. string(0) ""
  134. string(5) "fALSE"
  135. string(1) " "
  136. string(5) " "
  137. string(1) "b"
  138. string(2) "\t"
  139. string(1) " "
  140. string(2) "12"
  141. string(8) "12twelve"
  142. #### Testing miscellaneous inputs ####
  143. --- Testing lowercamelcase action call example ---
  144. string(%d) "partnerName"
  145. --- Testing objects ---
  146. string(11) "hello world"
  147. --- Testing a longer and heredoc string ---
  148. string(639) "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  149. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  150. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  151. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  152. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  153. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  154. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  155. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  156. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
  157. --- Testing a heredoc null string ---
  158. string(0) ""
  159. --- Testing simple and complex syntax strings ---
  160. string(5) "world"
  161. string(7) "world'S"
  162. Warning: Undefined variable $strS in %s on line %d
  163. string(0) ""
  164. string(6) "worldS"
  165. string(6) "worldS"
  166. --- Nested lcfirst() ---
  167. string(5) "hello"
  168. Done