preg_replace_error.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Test preg_replace() function : error - incorrect number of parameters
  3. --FILE--
  4. <?php
  5. /*
  6. * proto string preg_replace(mixed regex, mixed replace, mixed subject [, int limit [, count]])
  7. * Function is implemented in ext/pcre/php_pcre.c
  8. */
  9. echo "*** Testing preg_replace() : error conditions ***\n";
  10. //Zero arguments
  11. echo "\n-- Testing preg_replace() function with zero arguments --\n";
  12. var_dump(preg_replace());
  13. //Test preg_replace() with one more than the expected number of arguments
  14. echo "\n-- Testing preg_replace() function with more than expected no. of arguments --\n";
  15. $regex = '/\w/';
  16. $replace = '1';
  17. $subject = 'string_val';
  18. $limit = 10;
  19. $extra_arg = 10;
  20. var_dump(preg_replace($regex, $replace, $subject, $limit, $count, $extra_arg));
  21. //Testing preg_replace() with one less than the expected number of arguments
  22. echo "\n-- Testing preg_replace() function with less than expected no. of arguments --\n";
  23. $regex = '/\w/';
  24. $replace = '1';
  25. var_dump(preg_replace($regex, $replace));
  26. echo "Done"
  27. ?>
  28. --EXPECTF--
  29. *** Testing preg_replace() : error conditions ***
  30. -- Testing preg_replace() function with zero arguments --
  31. Warning: preg_replace() expects at least 3 parameters, 0 given in %s on line %d
  32. NULL
  33. -- Testing preg_replace() function with more than expected no. of arguments --
  34. Warning: preg_replace() expects at most 5 parameters, 6 given in %s on line %d
  35. NULL
  36. -- Testing preg_replace() function with less than expected no. of arguments --
  37. Warning: preg_replace() expects at least 3 parameters, 2 given in %s on line %d
  38. NULL
  39. Done