@@ -3,21 +3,25 @@ Test preg_grep() function : error conditions - bad regular expressions
33--FILE--
44<?php
55/*
6- * Function is implemented in ext/pcre/php_pcre.c
7- */
6+ * Function is implemented in ext/pcre/php_pcre.c
7+ */
88/*
9- * Testing how preg_grep reacts to being passed bad regexes
10- */
11- echo "*** Testing preg_grep() : error conditions *** \n" ;
12- $ values = 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- $ array = array (123 , 'abc ' , 'test ' );
19- foreach ($ values as $ value ) {
20- @print "\nArg value is $ value \n" ;
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 ' ];
24+ foreach ($ values as $ value ) {
2125 try {
2226 var_dump (preg_grep ($ value , $ array ));
2327 } catch (TypeError $ e ) {
@@ -30,40 +34,25 @@ try {
3034} catch (TypeError $ e ) {
3135 echo $ e ->getMessage (), "\n" ;
3236}
33- echo "Done "
3437?>
3538--EXPECTF--
36- *** Testing preg_grep() : error conditions ***
3739
38- Arg value is abcdef
39-
40- Warning: preg_grep(): Delimiter must not be alphanumeric, backslash, or NUL in %spreg_grep_error1.php on line %d
40+ Warning: preg_grep(): Delimiter must not be alphanumeric, backslash, or NUL byte in %spreg_grep_error1.php on line %d
4141bool(false)
4242
43- Arg value is /[a-zA-Z]
44-
4543Warning: preg_grep(): No ending delimiter '/' found in %spreg_grep_error1.php on line %d
4644bool(false)
4745
48- Arg value is [a-zA-Z]/
49-
5046Warning: preg_grep(): Unknown modifier '/' in %spreg_grep_error1.php on line %d
5147bool(false)
5248
53- Arg value is /[a-zA-Z]/F
54-
5549Warning: preg_grep(): Unknown modifier 'F' in %spreg_grep_error1.php on line %d
5650bool(false)
57-
58- Arg value is Array
5951preg_grep(): Argument #1 ($pattern) must be of type string, array given
60-
61- Arg value is /[a-zA-Z]/
6252array(2) {
6353 [1]=>
6454 string(3) "abc"
6555 [2]=>
6656 string(4) "test"
6757}
6858preg_grep(): Argument #1 ($pattern) must be of type string, stdClass given
69- Done
0 commit comments