mb_substr_error1.phpt 1.5 KB

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