1--TEST--
2Test preg_match_all() function : error conditions - bad regular expressions
3--FILE--
4<?php
5/*
6* proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
7* Function is implemented in ext/pcre/php_pcre.c
8*/
9error_reporting(E_ALL&~E_NOTICE);
10/*
11* Testing how preg_match_all reacts to being passed the wrong type of regex argument
12*/
13echo "*** Testing preg_match_all() : error conditions ***\n";
14$regex_array = 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$subject = 'test';
21foreach($regex_array as $regex_value) {
22    print "\nArg value is $regex_value\n";
23    var_dump(preg_match_all($regex_value, $subject, $matches1));
24    var_dump($matches1);
25}
26$regex_value = new stdclass(); //Object
27var_dump(preg_match_all($regex_value, $subject, $matches));
28var_dump($matches);
29?>
30--EXPECTF--
31*** Testing preg_match_all() : error conditions ***
32
33Arg value is abcdef
34
35Warning: preg_match_all(): Delimiter must not be alphanumeric or backslash in %spreg_match_all_error1.php on line %d
36bool(false)
37NULL
38
39Arg value is /[a-zA-Z]
40
41Warning: preg_match_all(): No ending delimiter '/' found in %spreg_match_all_error1.php on line %d
42bool(false)
43NULL
44
45Arg value is [a-zA-Z]/
46
47Warning: preg_match_all(): Unknown modifier '/' in %spreg_match_all_error1.php on line %d
48bool(false)
49NULL
50
51Arg value is /[a-zA-Z]/F
52
53Warning: preg_match_all(): Unknown modifier 'F' in %spreg_match_all_error1.php on line %d
54bool(false)
55NULL
56
57Arg value is Array
58
59Warning: preg_match_all() expects parameter 1 to be string, array given in %spreg_match_all_error1.php on line %d
60bool(false)
61NULL
62
63Arg value is /[a-zA-Z]/
64int(4)
65array(1) {
66  [0]=>
67  array(4) {
68    [0]=>
69    string(1) "t"
70    [1]=>
71    string(1) "e"
72    [2]=>
73    string(1) "s"
74    [3]=>
75    string(1) "t"
76  }
77}
78
79Warning: preg_match_all() expects parameter 1 to be string, object given in %spreg_match_all_error1.php on line %d
80bool(false)
81NULL
82