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*/
11echo "*** Testing preg_replace() : 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$replace = 1;
19$subject = 'a';
20foreach($regex_array as $regex_value) {
21    @print "\nArg value is $regex_value\n";
22    var_dump(preg_replace($regex_value, $replace, $subject));
23}
24$regex_value = new stdclass(); //Object
25try {
26    var_dump(preg_replace($regex_value, $replace, $subject));
27} catch (Error $e) {
28    echo $e->getMessage(), "\n";
29}
30?>
31--EXPECTF--
32*** Testing preg_replace() : error conditions***
33
34Arg value is abcdef
35
36Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in %spreg_replace_error1.php on line %d
37NULL
38
39Arg value is /[a-zA-Z]
40
41Warning: preg_replace(): No ending delimiter '/' found in %spreg_replace_error1.php on line %d
42NULL
43
44Arg value is [a-zA-Z]/
45
46Warning: preg_replace(): Unknown modifier '/' in %spreg_replace_error1.php on line %d
47NULL
48
49Arg value is /[a-zA-Z]/F
50
51Warning: preg_replace(): Unknown modifier 'F' in %spreg_replace_error1.php on line %d
52NULL
53
54Arg value is Array
55string(1) "a"
56
57Arg value is /[a-zA-Z]/
58string(1) "1"
59preg_replace(): Argument #1 ($pattern) must be of type array|string, stdClass given
60