Skip to content

Commit ea87d04

Browse files
committed
Promote warnings to exceptions in ext/pcre
Closes GH-6006
1 parent 2369f48 commit ea87d04

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

ext/pcre/php_pcre.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,8 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
11931193
}
11941194
if ((global && (subpats_order < PREG_PATTERN_ORDER || subpats_order > PREG_SET_ORDER)) ||
11951195
(!global && subpats_order != 0)) {
1196-
php_error_docref(NULL, E_WARNING, "Invalid flags specified");
1197-
return;
1196+
zend_argument_value_error(4, "must be a PREG_* constant");
1197+
RETURN_THROWS();
11981198
}
11991199
} else {
12001200
offset_capture = 0;
@@ -2410,9 +2410,7 @@ PHP_FUNCTION(preg_replace_callback_array)
24102410
}
24112411

24122412
if (!zend_is_callable_ex(replace, NULL, 0, NULL, &fcc, NULL)) {
2413-
zend_string *callback_name = zend_get_callable_name(replace);
2414-
zend_type_error("'%s' is not a valid callback", ZSTR_VAL(callback_name));
2415-
zend_string_release_ex(callback_name, 0);
2413+
zend_argument_type_error(1, "must contain only valid callbacks");
24162414
RETURN_THROWS();
24172415
}
24182416

ext/pcre/tests/002.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ preg_* with bogus vals
33
--FILE--
44
<?php
55

6-
var_dump(preg_match_all('//', '', $dummy, 0xdead));
6+
try {
7+
preg_match_all('//', '', $dummy, 0xdead);
8+
} catch (ValueError $exception) {
9+
echo $exception->getMessage() . "\n";
10+
}
711

812
var_dump(preg_quote(''));
913

@@ -13,8 +17,7 @@ var_dump(preg_replace('/(.)/e', 'for ($', 'abc'));
1317

1418
?>
1519
--EXPECTF--
16-
Warning: preg_match_all(): Invalid flags specified in %s002.php on line %d
17-
NULL
20+
preg_match_all(): Argument #4 ($flags) must be a PREG_* constant
1821
string(0) ""
1922
string(12) "a${1b${1c${1"
2023

ext/pcre/tests/preg_replace_callback_array2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ try {
3030
echo "Done\n";
3131
?>
3232
--EXPECTF--
33-
's' is not a valid callback
33+
preg_replace_callback_array(): Argument #1 ($pattern) must contain only valid callbacks
3434
string(0) ""
3535

3636
Warning: preg_replace_callback_array(): No ending delimiter '/' found in %spreg_replace_callback_array2.php on line %d

0 commit comments

Comments
 (0)