PageRenderTime 34ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 128 lines | 75 code | 25 blank | 28 comment | 2 complexity | b18b2d306ad185b39d36000245052f9d 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. /* Prototype : string strrchr(string $haystack, string $needle);
  3. * Description: Finds the last occurrence of a character in a string.
  4. * Source code: ext/standard/string.c
  5. */
  6. /* Test strrchr() function: with unexpected inputs for needle
  7. * and expected type for haystack
  8. */
  9. echo "*** Testing strrchr() function with unexpected inputs for needle ***\n";
  10. // get an unset variable
  11. $unset_var = 'string_val';
  12. unset($unset_var);
  13. // declaring a class
  14. class sample {
  15. public function __toString() {
  16. return "object";
  17. }
  18. }
  19. //getting the resource
  20. $file_handle = fopen(__FILE__, "r");
  21. $haystacks = array (
  22. //integer numeric strings
  23. "0",
  24. "1",
  25. "2",
  26. "-2",
  27. //float numeric strings
  28. "10.5",
  29. "-10.5",
  30. "10.5e10",
  31. "10.6E-10",
  32. ".5",
  33. //regular strings
  34. "array",
  35. "a",
  36. "r",
  37. "y",
  38. "ay",
  39. "true",
  40. "false",
  41. "TRUE",
  42. "FALSE",
  43. "NULL",
  44. "null",
  45. "object",
  46. //empty string
  47. "",
  48. '',
  49. //resource variable in string form
  50. "\$file_handle",
  51. //undefined variable in string form
  52. @"$undefined_var",
  53. @"$unset_var"
  54. );
  55. // array with different values
  56. $needles = array (
  57. // integer values
  58. 0,
  59. 1,
  60. 12345,
  61. -2345,
  62. // float values
  63. 10.5,
  64. -10.5,
  65. 10.1234567e10,
  66. 10.7654321E-10,
  67. .5,
  68. // array values
  69. array(),
  70. array(0),
  71. array(1),
  72. array(1, 2),
  73. array('color' => 'red', 'item' => 'pen'),
  74. // boolean values
  75. true,
  76. false,
  77. TRUE,
  78. FALSE,
  79. // null vlaues
  80. NULL,
  81. null,
  82. // objects
  83. new sample(),
  84. // empty string
  85. "",
  86. '',
  87. // resource
  88. $file_handle,
  89. // undefined variable
  90. @$undefined_var,
  91. // unset variable
  92. @$unset_var
  93. );
  94. // loop through each element of the array and check the working of strrchr()
  95. $count = 1;
  96. for($index = 0; $index < count($haystacks); $index++) {
  97. echo "-- Iteration $count --\n";
  98. var_dump( strrchr($haystacks[$index], $needles[$index]) );
  99. $count ++;
  100. }
  101. fclose($file_handle); //closing the file handle
  102. echo "*** Done ***";
  103. ?>