1--TEST--
2Test preg_match_all() 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_match_all reacts to being passed the wrong type of regex argument
10*/
11echo "*** Testing preg_match_all() : error conditions ***\n";
12$regex_array = 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$subject = 'test';
19foreach($regex_array as $regex_value) {
20    @print "\nArg value is $regex_value\n";
21    try {
22        var_dump(preg_match_all($regex_value, $subject, $matches1));
23    } catch (TypeError $e) {
24        echo $e->getMessage(), "\n";
25    }
26    var_dump($matches1);
27}
28$regex_value = new stdclass(); //Object
29try {
30    var_dump(preg_match_all($regex_value, $subject, $matches));
31} catch (TypeError $e) {
32    echo $e->getMessage(), "\n";
33}
34var_dump($matches);
35?>
36--EXPECTF--
37*** Testing preg_match_all() : error conditions ***
38
39Arg value is abcdef
40
41Warning: preg_match_all(): Delimiter must not be alphanumeric, backslash, or NUL in %spreg_match_all_error1.php on line %d
42bool(false)
43NULL
44
45Arg value is /[a-zA-Z]
46
47Warning: preg_match_all(): No ending delimiter '/' found in %spreg_match_all_error1.php on line %d
48bool(false)
49NULL
50
51Arg value is [a-zA-Z]/
52
53Warning: preg_match_all(): Unknown modifier '/' in %spreg_match_all_error1.php on line %d
54bool(false)
55NULL
56
57Arg value is /[a-zA-Z]/F
58
59Warning: preg_match_all(): Unknown modifier 'F' in %spreg_match_all_error1.php on line %d
60bool(false)
61NULL
62
63Arg value is Array
64preg_match_all(): Argument #1 ($pattern) must be of type string, array given
65NULL
66
67Arg value is /[a-zA-Z]/
68int(4)
69array(1) {
70  [0]=>
71  array(4) {
72    [0]=>
73    string(1) "t"
74    [1]=>
75    string(1) "e"
76    [2]=>
77    string(1) "s"
78    [3]=>
79    string(1) "t"
80  }
81}
82preg_match_all(): Argument #1 ($pattern) must be of type string, stdClass given
83NULL
84