preg_grep_error2.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. Test preg_grep() function : error conditions - wrong arg types
  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 the wrong type of input argument
  12. */
  13. echo "*** Testing preg_grep() : error conditions ***\n";
  14. $regex = '/[a-zA-Z]/';
  15. $input = array('this is a string', array('this is', 'a subarray'),);
  16. foreach($input as $value) {
  17. print "\nArg value is: $value\n";
  18. var_dump(preg_grep($regex, $value));
  19. }
  20. $value = new stdclass(); //Object
  21. var_dump(preg_grep($regex, $value));
  22. echo "Done";
  23. ?>
  24. --EXPECTF--
  25. *** Testing preg_grep() : error conditions ***
  26. Arg value is: this is a string
  27. Warning: preg_grep() expects parameter 2 to be array, string given in %spreg_grep_error2.php on line %d
  28. NULL
  29. Arg value is: Array
  30. array(2) {
  31. [0]=>
  32. string(7) "this is"
  33. [1]=>
  34. string(10) "a subarray"
  35. }
  36. Warning: preg_grep() expects parameter 2 to be array, object given in %spreg_grep_error2.php on line %d
  37. NULL
  38. Done