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 */
11$regex_array = [
12    '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',
16    [
17        '[a-z]', //Array of Regexes
18        '[A-Z]',
19        '[0-9]',
20    ],
21    '/[a-zA-Z]/', //Regex string
22];
23$subject = 'test';
24foreach ($regex_array as $regex_value) {
25    try {
26        var_dump(preg_match_all($regex_value, $subject, $matches1));
27    } catch (TypeError $e) {
28        echo $e->getMessage(), "\n";
29    }
30    var_dump($matches1);
31}
32$regex_value = new stdclass(); //Object
33try {
34    var_dump(preg_match_all($regex_value, $subject, $matches));
35} catch (TypeError $e) {
36    echo $e->getMessage(), "\n";
37}
38var_dump($matches);
39?>
40--EXPECTF--
41
42Warning: preg_match_all(): Delimiter must not be alphanumeric, backslash, or NUL byte in %spreg_match_all_error1.php on line %d
43bool(false)
44NULL
45
46Warning: preg_match_all(): No ending delimiter '/' found in %spreg_match_all_error1.php on line %d
47bool(false)
48NULL
49
50Warning: preg_match_all(): Unknown modifier '/' in %spreg_match_all_error1.php on line %d
51bool(false)
52NULL
53
54Warning: preg_match_all(): Unknown modifier 'F' in %spreg_match_all_error1.php on line %d
55bool(false)
56NULL
57preg_match_all(): Argument #1 ($pattern) must be of type string, array given
58NULL
59int(4)
60array(1) {
61  [0]=>
62  array(4) {
63    [0]=>
64    string(1) "t"
65    [1]=>
66    string(1) "e"
67    [2]=>
68    string(1) "s"
69    [3]=>
70    string(1) "t"
71  }
72}
73preg_match_all(): Argument #1 ($pattern) must be of type string, stdClass given
74NULL
75