mb_strpos_error1.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --TEST--
  2. Test mb_strpos() function : error conditions - Pass incorrect number of args
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_strpos(string $haystack, string $needle [, int $offset [, string $encoding]])
  11. * Description: Find position of first occurrence of a string within another
  12. * Source code: ext/mbstring/mbstring.c
  13. */
  14. /*
  15. * Test how mb_strpos behaves when passed an incorrect number of arguments
  16. */
  17. echo "*** Testing mb_strpos() : error conditions ***\n";
  18. //Test mb_strpos with one more than the expected number of arguments
  19. echo "\n-- Testing mb_strpos() function with more than expected no. of arguments --\n";
  20. $haystack = 'string_val';
  21. $needle = 'string_val';
  22. $offset = 10;
  23. $encoding = 'string_val';
  24. $extra_arg = 10;
  25. var_dump( mb_strpos($haystack, $needle, $offset, $encoding, $extra_arg) );
  26. // Testing mb_strpos with one less than the expected number of arguments
  27. echo "\n-- Testing mb_strpos() function with less than expected no. of arguments --\n";
  28. $haystack = 'string_val';
  29. var_dump( mb_strpos($haystack) );
  30. echo "Done";
  31. ?>
  32. --EXPECTF--
  33. *** Testing mb_strpos() : error conditions ***
  34. -- Testing mb_strpos() function with more than expected no. of arguments --
  35. Warning: mb_strpos() expects at most 4 parameters, 5 given in %s on line %d
  36. bool(false)
  37. -- Testing mb_strpos() function with less than expected no. of arguments --
  38. Warning: mb_strpos() expects at least 2 parameters, 1 given in %s on line %d
  39. bool(false)
  40. Done