PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 128 lines | 75 code | 25 blank | 28 comment | 2 complexity | 6d764b889a56b322cf49941efd26a7bc 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 haystack
  7. * and expected type for 'needle'
  8. */
  9. echo "*** Testing strrchr() function: with unexpected inputs for haystack ***\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. // array with different values
  22. $haystacks = array (
  23. // integer values
  24. 0,
  25. 1,
  26. 12345,
  27. -2345,
  28. // float values
  29. 10.5,
  30. -10.5,
  31. 10.5e10,
  32. 10.6E-10,
  33. .5,
  34. // array values
  35. array(),
  36. array(0),
  37. array(1),
  38. array(1, 2),
  39. array('color' => 'red', 'item' => 'pen'),
  40. // boolean values
  41. true,
  42. false,
  43. TRUE,
  44. FALSE,
  45. // null vlaues
  46. NULL,
  47. null,
  48. // objects
  49. new sample(),
  50. // empty string
  51. "",
  52. '',
  53. // resource
  54. $file_handle,
  55. // undefined variable
  56. @$undefined_var,
  57. // unset variable
  58. @$unset_var
  59. );
  60. $needles = array (
  61. //integer numeric strings
  62. "0",
  63. "1",
  64. "2",
  65. "-2",
  66. //float numeric strings
  67. "10.5",
  68. "-10.5",
  69. "10.5e10",
  70. "10.6E-10",
  71. ".5",
  72. //regular strings
  73. "array",
  74. "a",
  75. "r",
  76. "y",
  77. "ay",
  78. "true",
  79. "false",
  80. "TRUE",
  81. "FALSE",
  82. "NULL",
  83. "null",
  84. "object",
  85. //empty string
  86. "",
  87. '',
  88. //resource variable in string form
  89. "\$file_handle",
  90. //undefined variable in string form
  91. @"$undefined_var",
  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. ?>