1--TEST--
2Test preg_replace() function : error - bad regular expressions
3--FILE--
4<?php
5/*
6 * Function is implemented in ext/pcre/php_pcre.c
7 */
8/*
9 * Testing how preg_replace 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$replace = 1;
24$subject = 'a';
25foreach ($regex_array as $regex_value) {
26    var_dump(preg_replace($regex_value, $replace, $subject));
27}
28$regex_value = new stdclass(); //Object
29try {
30    var_dump(preg_replace($regex_value, $replace, $subject));
31} catch (Error $e) {
32    echo $e->getMessage(), "\n";
33}
34?>
35--EXPECTF--
36
37Warning: preg_replace(): Delimiter must not be alphanumeric, backslash, or NUL byte in %spreg_replace_error1.php on line %d
38NULL
39
40Warning: preg_replace(): No ending delimiter '/' found in %spreg_replace_error1.php on line %d
41NULL
42
43Warning: preg_replace(): Unknown modifier '/' in %spreg_replace_error1.php on line %d
44NULL
45
46Warning: preg_replace(): Unknown modifier 'F' in %spreg_replace_error1.php on line %d
47NULL
48string(1) "a"
49string(1) "1"
50preg_replace(): Argument #1 ($pattern) must be of type array|string, stdClass given
51