1--TEST--
2Test preg_grep() function : error conditions - bad regular expressions
3--FILE--
4<?php
5/*
6* Function is implemented in ext/pcre/php_pcre.c
7*/
8/*
9* Testing how preg_grep reacts to being passed bad regexes
10*/
11echo "*** Testing preg_grep() : error conditions ***\n";
12$values = array('abcdef', //Regex without delimiter
13'/[a-zA-Z]', //Regex without closing delimiter
14'[a-zA-Z]/', //Regex without opening delimiter
15'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
16'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
17);
18$array = array(123, 'abc', 'test');
19foreach($values as $value) {
20    @print "\nArg value is $value\n";
21    try {
22        var_dump(preg_grep($value, $array));
23    } catch (TypeError $e) {
24        echo $e->getMessage(), "\n";
25    }
26}
27$value = new stdclass(); //Object
28try {
29    var_dump(preg_grep($value, $array));
30} catch (TypeError $e) {
31    echo $e->getMessage(), "\n";
32}
33echo "Done"
34?>
35--EXPECTF--
36*** Testing preg_grep() : error conditions ***
37
38Arg value is abcdef
39
40Warning: preg_grep(): Delimiter must not be alphanumeric or backslash in %spreg_grep_error1.php on line %d
41bool(false)
42
43Arg value is /[a-zA-Z]
44
45Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
46bool(false)
47
48Arg value is [a-zA-Z]/
49
50Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d
51bool(false)
52
53Arg value is /[a-zA-Z]/F
54
55Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
56bool(false)
57
58Arg value is Array
59preg_grep(): Argument #1 ($pattern) must be of type string, array given
60
61Arg value is /[a-zA-Z]/
62array(2) {
63  [1]=>
64  string(3) "abc"
65  [2]=>
66  string(4) "test"
67}
68preg_grep(): Argument #1 ($pattern) must be of type string, stdClass given
69Done
70