PageRenderTime 41ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mbstring/tests/mb_strstr_variation4.php

http://github.com/facebook/hiphop-php
PHP | 112 lines | 63 code | 24 blank | 25 comment | 2 complexity | 2555ecc45671e3f560a0a626cf283f3f 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 mb_strstr(string haystack, string needle[, bool part[, string encoding]])
  3. * Description: Finds first occurrence of a string within another
  4. * Source code: ext/mbstring/mbstring.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing mb_strstr() : usage variation ***\n";
  8. // Define error handler
  9. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  10. if (error_reporting() != 0) {
  11. // report non-silenced errors
  12. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  13. }
  14. }
  15. set_error_handler('test_error_handler');
  16. // Initialise function arguments not being substituted (if any)
  17. $haystack = b'string_val';
  18. $needle = b'_';
  19. $part = true;
  20. //get an unset variable
  21. $unset_var = 10;
  22. unset ($unset_var);
  23. // define some classes
  24. class classWithToString
  25. {
  26. public function __toString() {
  27. return "invalid";
  28. }
  29. }
  30. class classWithoutToString
  31. {
  32. }
  33. // heredoc string
  34. $heredoc = <<<EOT
  35. invalid
  36. EOT;
  37. // get a resource variable
  38. $fp = fopen(__FILE__, "r");
  39. // add arrays
  40. $index_array = array (1, 2, 3);
  41. $assoc_array = array ('one' => 1, 'two' => 2);
  42. //array of values to iterate over
  43. $inputs = array(
  44. // int data
  45. 'int 0' => 0,
  46. 'int 1' => 1,
  47. 'int 12345' => 12345,
  48. 'int -12345' => -2345,
  49. // float data
  50. 'float 10.5' => 10.5,
  51. 'float -10.5' => -10.5,
  52. 'float 12.3456789000e10' => 12.3456789000e10,
  53. 'float -12.3456789000e10' => -12.3456789000e10,
  54. 'float .5' => .5,
  55. // array data
  56. 'empty array' => array(),
  57. 'int indexed array' => $index_array,
  58. 'associative array' => $assoc_array,
  59. 'nested arrays' => array('foo', $index_array, $assoc_array),
  60. // null data
  61. 'uppercase NULL' => NULL,
  62. 'lowercase null' => null,
  63. // boolean data
  64. 'lowercase true' => true,
  65. 'lowercase false' =>false,
  66. 'uppercase TRUE' =>TRUE,
  67. 'uppercase FALSE' =>FALSE,
  68. // empty data
  69. 'empty string DQ' => "",
  70. 'empty string SQ' => '',
  71. // object data
  72. 'instance of classWithToString' => new classWithToString(),
  73. 'instance of classWithoutToString' => new classWithoutToString(),
  74. // undefined data
  75. 'undefined var' => @$undefined_var,
  76. // unset data
  77. 'unset var' => @$unset_var,
  78. // resource variable
  79. 'resource' => $fp
  80. );
  81. // loop through each element of the array for encoding
  82. foreach($inputs as $key =>$value) {
  83. echo "\n--$key--\n";
  84. var_dump( mb_strstr($haystack, $needle, $part, $value) );
  85. };
  86. fclose($fp);
  87. ?>
  88. ===DONE===