PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 158 lines | 123 code | 26 blank | 9 comment | 3 complexity | de8360160449ac6a2951d9211e50c7b8 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 lcfirst.",
  6. "1.testing lcfirst",
  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 lcfirst with different values */
  39. foreach ($str_array as $string) {
  40. var_dump( lcfirst($string) );
  41. }
  42. echo "\n#### Testing Miscelleneous inputs ####\n";
  43. echo "--- Testing arrays ---";
  44. $str_arr = array("Hello", "?world", "!$%**()%**[][[[&@#~!", array());
  45. var_dump( lcfirst($str_arr) );
  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 "Catchable 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 string {
  74. function __toString() {
  75. return "Hello world";
  76. }
  77. }
  78. $obj_string = new string;
  79. var_dump(lcfirst("$obj_string"));
  80. echo "\n--- Testing Resources ---\n";
  81. $filename1 = "dummy.txt";
  82. $file1 = fopen($filename1, "w"); // creating new file
  83. /* getting resource type for file handle */
  84. $string1 = get_resource_type($file1);
  85. $string2 = (int)get_resource_type($file1); // converting stream type to int
  86. /* $string1 is of "stream" type */
  87. var_dump(lcfirst($string1));
  88. /* $string2 holds a value of "int(0)" */
  89. var_dump(lcfirst($string2));
  90. fclose($file1); // closing the file "dummy.txt"
  91. unlink("$filename1"); // deletes "dummy.txt"
  92. echo "\n--- Testing a longer and heredoc string ---\n";
  93. $string = <<<EOD
  94. Abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  95. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  96. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  97. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  98. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  99. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  100. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  101. @#$%^&**&^%$#@!~:())))((((&&&**%$###@@@!!!~~~~@###$%^&*
  102. abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
  103. EOD;
  104. var_dump(lcfirst($string));
  105. echo "\n--- Testing a heredoc null string ---\n";
  106. $str = <<<EOD
  107. EOD;
  108. var_dump(lcfirst($str));
  109. echo "\n--- Testing simple and complex syntax strings ---\n";
  110. $str = 'world';
  111. /* Simple syntax */
  112. var_dump(lcfirst("$str"));
  113. var_dump(lcfirst("$str'S"));
  114. var_dump(lcfirst("$strS"));
  115. /* String with curly braces, complex syntax */
  116. var_dump(lcfirst("${str}S"));
  117. var_dump(lcfirst("{$str}S"));
  118. echo "\n--- Nested lcfirst() ---\n";
  119. var_dump(lcfirst(lcfirst("hello")));
  120. echo "\n#### error conditions ####";
  121. /* Zero arguments */
  122. lcfirst();
  123. /* More than expected no. of args */
  124. lcfirst($str_array[0], $str_array[1]);
  125. lcfirst((int)10, (int)20);
  126. echo "Done\n";
  127. ?>