1--TEST-- 2Test preg_grep() 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_grep reacts to being passed bad regexes 10 */ 11$values = [ 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$array = [123, 'abc', 'test']; 24foreach ($values as $value) { 25 try { 26 var_dump(preg_grep($value, $array)); 27 } catch (TypeError $e) { 28 echo $e->getMessage(), "\n"; 29 } 30} 31$value = new stdclass(); //Object 32try { 33 var_dump(preg_grep($value, $array)); 34} catch (TypeError $e) { 35 echo $e->getMessage(), "\n"; 36} 37?> 38--EXPECTF-- 39 40Warning: preg_grep(): Delimiter must not be alphanumeric, backslash, or NUL byte in %spreg_grep_error1.php on line %d 41bool(false) 42 43Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d 44bool(false) 45 46Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d 47bool(false) 48 49Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d 50bool(false) 51preg_grep(): Argument #1 ($pattern) must be of type string, array given 52array(2) { 53 [1]=> 54 string(3) "abc" 55 [2]=> 56 string(4) "test" 57} 58preg_grep(): Argument #1 ($pattern) must be of type string, stdClass given 59