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

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

http://github.com/facebook/hiphop-php
PHP | 87 lines | 47 code | 20 blank | 20 comment | 2 complexity | c9dd9fc4c9fff7b24ade2634370a0424 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 and needle */
  7. echo "*** Testing strrchr() function: with unexpected inputs for haystack and needle ***\n";
  8. // get an unset variable
  9. $unset_var = 'string_val';
  10. unset($unset_var);
  11. // declaring a class
  12. class sample {
  13. public function __toString() {
  14. return "object";
  15. }
  16. }
  17. //getting the resource
  18. $file_handle = fopen(__FILE__, "r");
  19. // array with different values
  20. $values = array (
  21. // integer values
  22. 0,
  23. 1,
  24. 12345,
  25. -2345,
  26. // float values
  27. 10.5,
  28. -10.5,
  29. 10.1234567e10,
  30. 10.7654321E-10,
  31. .5,
  32. // array values
  33. array(),
  34. array(0),
  35. array(1),
  36. array(1, 2),
  37. array('color' => 'red', 'item' => 'pen'),
  38. // boolean values
  39. true,
  40. false,
  41. TRUE,
  42. FALSE,
  43. // objects
  44. new sample(),
  45. // empty string
  46. "",
  47. '',
  48. // null vlaues
  49. NULL,
  50. null,
  51. // resource
  52. $file_handle,
  53. // undefined variable
  54. @$undefined_var,
  55. // unset variable
  56. @$unset_var
  57. );
  58. // loop through each element of the array and check the working of strrchr()
  59. $counter = 1;
  60. for($index = 0; $index < count($values); $index ++) {
  61. echo "-- Iteration $counter --\n";
  62. var_dump( strrchr($values[$index], $values[$index]) );
  63. $counter ++;
  64. }
  65. fclose($file_handle); //closing the file handle
  66. echo "*** Done ***";
  67. ?>