1--TEST-- 2Test 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*/ 9error_reporting(E_ALL&~E_NOTICE); 10/* 11* Testing how preg_grep reacts to being passed bad regexes 12*/ 13echo "*** Testing preg_grep() : error conditions ***\n"; 14$values = array('abcdef', //Regex without delimeter 15'/[a-zA-Z]', //Regex without closing delimeter 16'[a-zA-Z]/', //Regex without opening delimeter 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'); 21foreach($values as $value) { 22 print "\nArg value is $value\n"; 23 var_dump(preg_grep($value, $array)); 24} 25$value = new stdclass(); //Object 26var_dump(preg_grep($value, $array)); 27echo "Done" 28?> 29--EXPECTF-- 30 31*** Testing preg_grep() : error conditions *** 32 33Arg value is abcdef 34 35Warning: preg_grep(): Delimiter must not be alphanumeric or backslash in %spreg_grep_error1.php on line %d 36bool(false) 37 38Arg value is /[a-zA-Z] 39 40Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d 41bool(false) 42 43Arg value is [a-zA-Z]/ 44 45Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d 46bool(false) 47 48Arg value is /[a-zA-Z]/F 49 50Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d 51bool(false) 52 53Arg value is Array 54 55Warning: preg_grep() expects parameter 1 to be string, array given in %spreg_grep_error1.php on line %d 56NULL 57 58Arg value is /[a-zA-Z]/ 59array(2) { 60 [1]=> 61 string(3) "abc" 62 [2]=> 63 string(4) "test" 64} 65 66Warning: preg_grep() expects parameter 1 to be string, object given in %spreg_grep_error1.php on line %d 67NULL 68Done