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 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');
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*** Testing preg_grep() : error conditions ***
31
32Arg value is abcdef
33
34Warning: preg_grep(): Delimiter must not be alphanumeric or backslash in %spreg_grep_error1.php on line %d
35bool(false)
36
37Arg value is /[a-zA-Z]
38
39Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
40bool(false)
41
42Arg value is [a-zA-Z]/
43
44Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d
45bool(false)
46
47Arg value is /[a-zA-Z]/F
48
49Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
50bool(false)
51
52Arg value is Array
53
54Warning: preg_grep() expects parameter 1 to be string, array given in %spreg_grep_error1.php on line %d
55NULL
56
57Arg value is /[a-zA-Z]/
58array(2) {
59  [1]=>
60  string(3) "abc"
61  [2]=>
62  string(4) "test"
63}
64
65Warning: preg_grep() expects parameter 1 to be string, object given in %spreg_grep_error1.php on line %d
66NULL
67Done
68