Skip to content

Commit af1de14

Browse files
committed
Use ZPP string|array union check in PCRE extension
1 parent 9839752 commit af1de14

File tree

8 files changed

+145
-156
lines changed

8 files changed

+145
-156
lines changed

ext/pcre/php_pcre.c

Lines changed: 113 additions & 114 deletions
Large diffs are not rendered by default.

ext/pcre/php_pcre.stub.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,17 @@ function preg_match(string $pattern, string $subject, &$subpatterns = null, int
66

77
function preg_match_all(string $pattern, string $subject, &$subpatterns = null, int $flags = 0, int $offset = 0): int|false|null {}
88

9-
/**
10-
* @param string|array $regex
11-
* @param string|array $replace
12-
* @param string|array $subject
13-
*/
14-
function preg_replace($regex, $replace, $subject, int $limit = -1, &$count = null): string|array|null {}
15-
16-
/**
17-
* @param string|array $regex
18-
* @param string|array $replace
19-
* @param string|array $subject
20-
*/
21-
function preg_filter($regex, $replace, $subject, int $limit = -1, &$count = null): string|array|null {}
22-
23-
/**
24-
* @param string|array $regex
25-
* @param string|array $subject
26-
*/
27-
function preg_replace_callback($regex, callable $callback, $subject, int $limit = -1, &$count = null, int $flags = 0): string|array|null {}
9+
function preg_replace(string|array $regex, string|array $replace, string|array $subject, int $limit = -1, &$count = null): string|array|null {}
10+
11+
function preg_filter(string|array $regex, string|array $replace, string|array $subject, int $limit = -1, &$count = null): string|array|null {}
12+
13+
function preg_replace_callback(string|array $regex, callable $callback, string|array $subject, int $limit = -1, &$count = null, int $flags = 0): string|array|null {}
2814

2915
/** @param string|array $subject */
3016
function preg_replace_callback_array(array $pattern, $subject, int $limit = -1, &$count = null, int $flags = 0): string|array|null {}
3117

3218
function preg_split(string $pattern, string $subject, int $limit = -1, int $flags = 0): array|false {}
3319

34-
3520
function preg_quote(string $str, ?string $delim_char = null): string {}
3621

3722
function preg_grep(string $regex, array $input, int $flags = 0): array|false {}

ext/pcre/php_pcre_arginfo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 2e7402e33a485cd3c1a74c0d6210214b3e7c4e9a */
2+
* Stub hash: 88e664fe3f4714ab7760a99bffef5c11eafcf0aa */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_preg_match, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
@@ -18,19 +18,19 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_preg_match_all, 0, 2, MAY_BE_LON
1818
ZEND_END_ARG_INFO()
1919

2020
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_preg_replace, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_NULL)
21-
ZEND_ARG_INFO(0, regex)
22-
ZEND_ARG_INFO(0, replace)
23-
ZEND_ARG_INFO(0, subject)
21+
ZEND_ARG_TYPE_MASK(0, regex, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
22+
ZEND_ARG_TYPE_MASK(0, replace, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
23+
ZEND_ARG_TYPE_MASK(0, subject, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
2424
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, limit, IS_LONG, 0, "-1")
2525
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, count, "null")
2626
ZEND_END_ARG_INFO()
2727

2828
#define arginfo_preg_filter arginfo_preg_replace
2929

3030
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_preg_replace_callback, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_NULL)
31-
ZEND_ARG_INFO(0, regex)
31+
ZEND_ARG_TYPE_MASK(0, regex, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
3232
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
33-
ZEND_ARG_INFO(0, subject)
33+
ZEND_ARG_TYPE_MASK(0, subject, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
3434
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, limit, IS_LONG, 0, "-1")
3535
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, count, "null")
3636
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")

ext/pcre/tests/preg_replace_callback_array2.phpt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ preg_replace_callback_array() errors
55

66
$a = array();
77
$b = "";
8-
var_dump(preg_replace_callback_array(array("xx" => "s"), $a, -1, $b));
8+
9+
try {
10+
var_dump(preg_replace_callback_array(array("xx" => "s"), $a, -1, $b));
11+
} catch (\TypeError $e) {
12+
echo $e->getMessage() . \PHP_EOL;
13+
}
14+
15+
916
var_dump($b);
1017
function f() {
1118
static $count = 1;
@@ -23,9 +30,7 @@ try {
2330
echo "Done\n";
2431
?>
2532
--EXPECTF--
26-
Warning: preg_replace_callback_array(): 's' is not a valid callback in %spreg_replace_callback_array2.php on line %d
27-
array(0) {
28-
}
33+
's' is not a valid callback
2934
string(0) ""
3035

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

ext/pcre/tests/preg_replace_error1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ string(1) "a"
5656

5757
Arg value is /[a-zA-Z]/
5858
string(1) "1"
59-
Object of class stdClass could not be converted to string
59+
preg_replace(): Argument #1 ($regex) must be of type string|array, stdClass given

ext/pcre/tests/preg_replace_error2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ string(64) "this is a stringthis is a stringthis is a stringthis is a string"
3636

3737
Arg value is: Array
3838
preg_replace(): Argument #1 ($regex) must be of type array when argument #2 ($replace) is an array, string given
39-
Object of class stdClass could not be converted to string
39+
preg_replace(): Argument #2 ($replace) must be of type string|array, stdClass given
4040
Done

ext/standard/tests/streams/bug61115.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ $resourceFileTemp = fopen('php://temp', 'r+');
99
stream_context_set_params($resourceFileTemp, array());
1010
try {
1111
preg_replace('', function() {}, $resourceFileTemp);
12-
} catch (Error $e) {
12+
} catch (\TypeError $e) {
1313
echo $e->getMessage(), "\n";
1414
}
1515
?>
1616
--EXPECT--
17-
Object of class Closure could not be converted to string
17+
preg_replace(): Argument #2 ($replace) must be of type string|array, Closure given

sapi/cli/tests/006.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
9090
Function [ <internal:pcre> function preg_replace ] {
9191

9292
- Parameters [5] {
93-
Parameter #0 [ <required> $regex ]
94-
Parameter #1 [ <required> $replace ]
95-
Parameter #2 [ <required> $subject ]
93+
Parameter #0 [ <required> array|string $regex ]
94+
Parameter #1 [ <required> array|string $replace ]
95+
Parameter #2 [ <required> array|string $subject ]
9696
Parameter #3 [ <optional> int $limit = -1 ]
9797
Parameter #4 [ <optional> &$count = null ]
9898
}
@@ -101,9 +101,9 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
101101
Function [ <internal:pcre> function preg_filter ] {
102102

103103
- Parameters [5] {
104-
Parameter #0 [ <required> $regex ]
105-
Parameter #1 [ <required> $replace ]
106-
Parameter #2 [ <required> $subject ]
104+
Parameter #0 [ <required> array|string $regex ]
105+
Parameter #1 [ <required> array|string $replace ]
106+
Parameter #2 [ <required> array|string $subject ]
107107
Parameter #3 [ <optional> int $limit = -1 ]
108108
Parameter #4 [ <optional> &$count = null ]
109109
}
@@ -112,9 +112,9 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
112112
Function [ <internal:pcre> function preg_replace_callback ] {
113113

114114
- Parameters [6] {
115-
Parameter #0 [ <required> $regex ]
115+
Parameter #0 [ <required> array|string $regex ]
116116
Parameter #1 [ <required> callable $callback ]
117-
Parameter #2 [ <required> $subject ]
117+
Parameter #2 [ <required> array|string $subject ]
118118
Parameter #3 [ <optional> int $limit = -1 ]
119119
Parameter #4 [ <optional> &$count = null ]
120120
Parameter #5 [ <optional> int $flags = 0 ]

0 commit comments

Comments
 (0)