1--TEST--
2Test preg_match() function : error conditions - bad regular expressions
3--FILE--
4<?php
5/* Function is implemented in ext/pcre/php_pcre.c */
6/*
7* Testing how preg_match reacts to being passed the wrong type of regex argument
8*/
9echo "*** Testing preg_match() : error conditions ***\n";
10$regex_array = array('abcdef', //Regex without delimiter
11'/[a-zA-Z]', //Regex without closing delimiter
12'[a-zA-Z]/', //Regex without opening delimiter
13'/[a-zA-Z]/F', array('[a-z]', //Array of Regexes
14'[A-Z]', '[0-9]'), '/[a-zA-Z]/', //Regex string
15);
16$subject = 'this is a test';
17foreach($regex_array as $regex_value) {
18    @print "\nArg value is $regex_value\n";
19    try {
20        var_dump(preg_match($regex_value, $subject));
21    } catch (TypeError $e) {
22        echo $e->getMessage(), "\n";
23    }
24}
25$regex_value = new stdclass(); //Object
26try {
27    var_dump(preg_match($regex_value, $subject));
28} catch (TypeError $e) {
29    echo $e->getMessage(), "\n";
30}
31?>
32--EXPECTF--
33*** Testing preg_match() : error conditions ***
34
35Arg value is abcdef
36
37Warning: preg_match(): Delimiter must not be alphanumeric, backslash, or NUL in %spreg_match_error1.php on line %d
38bool(false)
39
40Arg value is /[a-zA-Z]
41
42Warning: preg_match(): No ending delimiter '/' found in %spreg_match_error1.php on line %d
43bool(false)
44
45Arg value is [a-zA-Z]/
46
47Warning: preg_match(): Unknown modifier '/' in %spreg_match_error1.php on line %d
48bool(false)
49
50Arg value is /[a-zA-Z]/F
51
52Warning: preg_match(): Unknown modifier 'F' in %spreg_match_error1.php on line %d
53bool(false)
54
55Arg value is Array
56preg_match(): Argument #1 ($pattern) must be of type string, array given
57
58Arg value is /[a-zA-Z]/
59int(1)
60preg_match(): Argument #1 ($pattern) must be of type string, stdClass given
61