preg_replace_error1.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. Test preg_replace() function : error - bad regular expressions
  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. error_reporting(E_ALL&~E_NOTICE);
  10. /*
  11. * Testing how preg_replace reacts to being passed the wrong type of regex argument
  12. */
  13. echo "*** Testing preg_replace() : error conditions***\n";
  14. $regex_array = array('abcdef', //Regex without delimiter
  15. '/[a-zA-Z]', //Regex without closing delimiter
  16. '[a-zA-Z]/', //Regex without opening delimiter
  17. '/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
  18. '[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
  19. );
  20. $replace = 1;
  21. $subject = 'a';
  22. foreach($regex_array as $regex_value) {
  23. print "\nArg value is $regex_value\n";
  24. var_dump(preg_replace($regex_value, $replace, $subject));
  25. }
  26. $regex_value = new stdclass(); //Object
  27. var_dump(preg_replace($regex_value, $replace, $subject));
  28. ?>
  29. --EXPECTF--
  30. *** Testing preg_replace() : error conditions***
  31. Arg value is abcdef
  32. Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in %spreg_replace_error1.php on line %d
  33. NULL
  34. Arg value is /[a-zA-Z]
  35. Warning: preg_replace(): No ending delimiter '/' found in %spreg_replace_error1.php on line %d
  36. NULL
  37. Arg value is [a-zA-Z]/
  38. Warning: preg_replace(): Unknown modifier '/' in %spreg_replace_error1.php on line %d
  39. NULL
  40. Arg value is /[a-zA-Z]/F
  41. Warning: preg_replace(): Unknown modifier 'F' in %spreg_replace_error1.php on line %d
  42. NULL
  43. Arg value is Array
  44. string(1) "a"
  45. Arg value is /[a-zA-Z]/
  46. string(1) "1"
  47. Catchable fatal error: Object of class stdClass could not be converted to string in %spreg_replace_error1.php on line %d