preg_grep_error1.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. Test preg_grep() function : error conditions - bad regular expressions
  3. --FILE--
  4. <?php
  5. /*
  6. * proto array preg_grep(string regex, array input [, int flags])
  7. * Function is implemented in ext/pcre/php_pcre.c
  8. */
  9. error_reporting(E_ALL&~E_NOTICE);
  10. /*
  11. * Testing how preg_grep reacts to being passed bad regexes
  12. */
  13. echo "*** Testing preg_grep() : error conditions ***\n";
  14. $values = 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. $array = array(123, 'abc', 'test');
  21. foreach($values as $value) {
  22. print "\nArg value is $value\n";
  23. var_dump(preg_grep($value, $array));
  24. }
  25. $value = new stdclass(); //Object
  26. var_dump(preg_grep($value, $array));
  27. echo "Done"
  28. ?>
  29. --EXPECTF--
  30. *** Testing preg_grep() : error conditions ***
  31. Arg value is abcdef
  32. Warning: preg_grep(): Delimiter must not be alphanumeric or backslash in %spreg_grep_error1.php on line %d
  33. bool(false)
  34. Arg value is /[a-zA-Z]
  35. Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
  36. bool(false)
  37. Arg value is [a-zA-Z]/
  38. Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d
  39. bool(false)
  40. Arg value is /[a-zA-Z]/F
  41. Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
  42. bool(false)
  43. Arg value is Array
  44. Warning: preg_grep() expects parameter 1 to be string, array given in %spreg_grep_error1.php on line %d
  45. NULL
  46. Arg value is /[a-zA-Z]/
  47. array(2) {
  48. [1]=>
  49. string(3) "abc"
  50. [2]=>
  51. string(4) "test"
  52. }
  53. Warning: preg_grep() expects parameter 1 to be string, object given in %spreg_grep_error1.php on line %d
  54. NULL
  55. Done