lcfirst.phpt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. string, // without quotes
  20. "-3",
  21. -3,
  22. '-3.344',
  23. -3.344,
  24. NULL,
  25. "NULL",
  26. "0",
  27. 0,
  28. TRUE, // bool type
  29. "TRUE",
  30. "1",
  31. 1,
  32. 1.234444,
  33. FALSE,
  34. "FALSE",
  35. " ",
  36. " ",
  37. 'b', // single char
  38. '\t', // escape sequences
  39. "\t",
  40. "12",
  41. "12twelve", // int + string
  42. );
  43. /* loop to test working of lcfirst with different values */
  44. foreach ($str_array as $string) {
  45. var_dump( lcfirst($string) );
  46. }
  47. echo "\n#### Testing Miscelleneous inputs ####\n";
  48. echo "--- Testing arrays ---";
  49. $str_arr = array("Hello", "?world", "!$%**()%**[][[[&@#~!", array());
  50. var_dump( lcfirst($str_arr) );
  51. echo "\n--- Testing lowercamelcase action call example ---\n";
  52. class Setter {
  53. protected $vars = array('partnerName' => false);
  54. public function __call($m, $v) {
  55. if (stristr($m, 'set')) {
  56. $action = lcfirst(substr($m, 3));
  57. $this->$action = $v[0];
  58. }
  59. }
  60. public function __set($key, $value) {
  61. if (array_key_exists($key, $this->vars)) {
  62. $this->vars[$key] = $value;
  63. }
  64. }
  65. public function __get($key) {
  66. if (array_key_exists($key, $this->vars)) {
  67. return $this->vars[$key];
  68. }
  69. }
  70. }
  71. $class = new Setter();
  72. $class->setPartnerName('partnerName');
  73. var_dump($class->partnerName);
  74. echo "\n--- Testing objects ---\n";
  75. /* we get "Catchable fatal error: saying Object of class could not be converted
  76. to string" by default when an object is passed instead of string:
  77. The error can be avoided by choosing the __toString magix method as follows: */
  78. class string {
  79. function __toString() {
  80. return "Hello world";
  81. }
  82. }
  83. $obj_string = new string;
  84. var_dump(lcfirst("$obj_string"));
  85. echo "\n--- Testing Resources ---\n";
  86. $filename1 = "dummy.txt";
  87. $file1 = fopen($filename1, "w"); // creating new file
  88. /* getting resource type for file handle */
  89. $string1 = get_resource_type($file1);
  90. $string2 = (int)get_resource_type($file1); // converting stream type to int
  91. /* $string1 is of "stream" type */
  92. var_dump(lcfirst($string1));
  93. /* $string2 holds a value of "int(0)" */
  94. var_dump(lcfirst($string2));
  95. fclose($file1); // closing the file "dummy.txt"
  96. unlink("$filename1"); // deletes "dummy.txt"
  97. echo "\n--- Testing a longer and heredoc string ---\n";
  98. $string = <<<EOD
  99. Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  100. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  101. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  102. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  103. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  104. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  105. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  106. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  107. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  108. EOD;
  109. var_dump(lcfirst($string));
  110. echo "\n--- Testing a heredoc null string ---\n";
  111. $str = <<<EOD
  112. EOD;
  113. var_dump(lcfirst($str));
  114. echo "\n--- Testing simple and complex syntax strings ---\n";
  115. $str = 'world';
  116. /* Simple syntax */
  117. var_dump(lcfirst("$str"));
  118. var_dump(lcfirst("$str'S"));
  119. var_dump(lcfirst("$strS"));
  120. /* String with curly braces, complex syntax */
  121. var_dump(lcfirst("${str}S"));
  122. var_dump(lcfirst("{$str}S"));
  123. echo "\n--- Nested lcfirst() ---\n";
  124. var_dump(lcfirst(lcfirst("hello")));
  125. echo "\n#### error conditions ####";
  126. /* Zero arguments */
  127. lcfirst();
  128. /* More than expected no. of args */
  129. lcfirst($str_array[0], $str_array[1]);
  130. lcfirst((int)10, (int)20);
  131. echo "Done\n";
  132. ?>
  133. --EXPECTF--
  134. #### Basic and Various operations ####
  135. Notice: Use of undefined constant string - assumed 'string' in %s on line %d
  136. string(16) "tesTing lcfirst."
  137. string(17) "1.testing lcfirst"
  138. string(11) "hELLO wORLD"
  139. string(11) "hELLO wORLD"
  140. string(1) "�"
  141. string(1) "�"
  142. string(2) "�0"
  143. string(4) "abcd"
  144. string(3) "xyz"
  145. string(6) "string"
  146. string(2) "-3"
  147. string(2) "-3"
  148. string(6) "-3.344"
  149. string(6) "-3.344"
  150. string(0) ""
  151. string(4) "nULL"
  152. string(1) "0"
  153. string(1) "0"
  154. string(1) "1"
  155. string(4) "tRUE"
  156. string(1) "1"
  157. string(1) "1"
  158. string(8) "1.234444"
  159. string(0) ""
  160. string(5) "fALSE"
  161. string(1) " "
  162. string(5) " "
  163. string(1) "b"
  164. string(2) "\t"
  165. string(1) " "
  166. string(2) "12"
  167. string(8) "12twelve"
  168. #### Testing Miscelleneous inputs ####
  169. --- Testing arrays ---
  170. Warning: lcfirst() expects parameter 1 to be string, array given in %s on line %d
  171. NULL
  172. --- Testing lowercamelcase action call example ---
  173. string(%d) "partnerName"
  174. --- Testing objects ---
  175. string(11) "hello world"
  176. --- Testing Resources ---
  177. string(6) "stream"
  178. string(1) "0"
  179. --- Testing a longer and heredoc string ---
  180. string(639) "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  181. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  182. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  183. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  184. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  185. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  186. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  187. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  188. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
  189. --- Testing a heredoc null string ---
  190. string(0) ""
  191. --- Testing simple and complex syntax strings ---
  192. string(5) "world"
  193. string(7) "world'S"
  194. Notice: Undefined variable: strS in %s on line %d
  195. string(0) ""
  196. string(6) "worldS"
  197. string(6) "worldS"
  198. --- Nested lcfirst() ---
  199. string(5) "hello"
  200. #### error conditions ####
  201. Warning: lcfirst() expects exactly 1 parameter, 0 given in %s on line %d
  202. Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d
  203. Warning: lcfirst() expects exactly 1 parameter, 2 given in %s on line %d
  204. Done