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 */ 9$regex_array = [ 10 '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', 14 [ 15 '[a-z]', //Array of Regexes 16 '[A-Z]', 17 '[0-9]', 18 ], 19 '/[a-zA-Z]/', //Regex string 20]; 21$subject = 'this is a test'; 22foreach ($regex_array as $regex_value) { 23 try { 24 var_dump(preg_match($regex_value, $subject)); 25 } catch (TypeError $e) { 26 echo $e->getMessage(), "\n"; 27 } 28} 29$regex_value = new stdclass(); //Object 30try { 31 var_dump(preg_match($regex_value, $subject)); 32} catch (TypeError $e) { 33 echo $e->getMessage(), "\n"; 34} 35 36?> 37--EXPECTF-- 38 39Warning: preg_match(): Delimiter must not be alphanumeric, backslash, or NUL byte in %spreg_match_error1.php on line %d 40bool(false) 41 42Warning: preg_match(): No ending delimiter '/' found in %spreg_match_error1.php on line %d 43bool(false) 44 45Warning: preg_match(): Unknown modifier '/' in %spreg_match_error1.php on line %d 46bool(false) 47 48Warning: preg_match(): Unknown modifier 'F' in %spreg_match_error1.php on line %d 49bool(false) 50preg_match(): Argument #1 ($pattern) must be of type string, array given 51int(1) 52preg_match(): Argument #1 ($pattern) must be of type string, stdClass given 53