From 3b6d1403053df6a9d6845571af32d496a4876f11 Mon Sep 17 00:00:00 2001 From: Stephen Reay Date: Sat, 10 Aug 2019 19:52:50 +0700 Subject: [PATCH 1/5] Add stubs for PCRE extension --- ext/pcre/php_pcre.c | 64 +------------------------------------ ext/pcre/php_pcre.stub.php | 55 +++++++++++++++++++++++++++++++ ext/pcre/php_pcre_arginfo.h | 57 +++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 63 deletions(-) create mode 100644 ext/pcre/php_pcre.stub.php create mode 100644 ext/pcre/php_pcre_arginfo.h diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 6c265df48507f..3842eecfb5a62 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2910,69 +2910,7 @@ static PHP_FUNCTION(preg_last_error) /* {{{ module definition structures */ -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_match, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, subject) - ZEND_ARG_INFO(1, subpatterns) /* array */ - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_match_all, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, subject) - ZEND_ARG_INFO(1, subpatterns) /* array */ - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace, 0, 0, 3) - ZEND_ARG_INFO(0, regex) - ZEND_ARG_INFO(0, replace) - ZEND_ARG_INFO(0, subject) - ZEND_ARG_INFO(0, limit) - ZEND_ARG_INFO(1, count) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback, 0, 0, 3) - ZEND_ARG_INFO(0, regex) - ZEND_ARG_INFO(0, callback) - ZEND_ARG_INFO(0, subject) - ZEND_ARG_INFO(0, limit) - ZEND_ARG_INFO(1, count) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback_array, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, subject) - ZEND_ARG_INFO(0, limit) - ZEND_ARG_INFO(1, count) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_split, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, subject) - ZEND_ARG_INFO(0, limit) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_quote, 0, 0, 1) - ZEND_ARG_INFO(0, str) - ZEND_ARG_INFO(0, delim_char) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_grep, 0, 0, 2) - ZEND_ARG_INFO(0, regex) - ZEND_ARG_INFO(0, input) /* array */ - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_preg_last_error, 0) -ZEND_END_ARG_INFO() -/* }}} */ +#include "php_pcre_arginfo.h" static const zend_function_entry pcre_functions[] = { PHP_FE(preg_match, arginfo_preg_match) diff --git a/ext/pcre/php_pcre.stub.php b/ext/pcre/php_pcre.stub.php new file mode 100644 index 0000000000000..189b942a5603a --- /dev/null +++ b/ext/pcre/php_pcre.stub.php @@ -0,0 +1,55 @@ + Date: Sat, 10 Aug 2019 21:36:25 +0700 Subject: [PATCH 2/5] Fix include position. --- ext/pcre/php_pcre.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 3842eecfb5a62..6002eedc782e8 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -20,6 +20,7 @@ #include "php_ini.h" #include "php_globals.h" #include "php_pcre.h" +#include "php_pcre_arginfo.h" #include "ext/standard/info.h" #include "ext/standard/basic_functions.h" #include "zend_smart_str.h" @@ -2910,8 +2911,6 @@ static PHP_FUNCTION(preg_last_error) /* {{{ module definition structures */ -#include "php_pcre_arginfo.h" - static const zend_function_entry pcre_functions[] = { PHP_FE(preg_match, arginfo_preg_match) PHP_FE(preg_match_all, arginfo_preg_match_all) From 378bca8e6c2e5219706857bc5706680ffaa28a74 Mon Sep 17 00:00:00 2001 From: Stephen Reay Date: Sat, 10 Aug 2019 22:10:52 +0700 Subject: [PATCH 3/5] Remove types on reference params & fix default for `$subpatterns` --- ext/pcre/php_pcre.stub.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/pcre/php_pcre.stub.php b/ext/pcre/php_pcre.stub.php index 189b942a5603a..a8d9c9b3a53ad 100644 --- a/ext/pcre/php_pcre.stub.php +++ b/ext/pcre/php_pcre.stub.php @@ -1,10 +1,10 @@ Date: Sun, 11 Aug 2019 00:08:52 +0700 Subject: [PATCH 4/5] Updated default values for ref params --- ext/pcre/php_pcre.stub.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/pcre/php_pcre.stub.php b/ext/pcre/php_pcre.stub.php index a8d9c9b3a53ad..46fb9274eb0c1 100644 --- a/ext/pcre/php_pcre.stub.php +++ b/ext/pcre/php_pcre.stub.php @@ -12,7 +12,7 @@ function preg_match_all(string $pattern, string $subject, &$subpatterns = null, * @param string|array $subject * @return string|array|null */ -function preg_replace($regex, $replace, $subject, int $limit = 0, &$count = 0) {} +function preg_replace($regex, $replace, $subject, int $limit = 0, &$count = null) {} /** * @param string|array $regex @@ -20,7 +20,7 @@ function preg_replace($regex, $replace, $subject, int $limit = 0, &$count = 0) { * @param string|array $subject * @return string|array|null */ -function preg_filter($regex, $replace, $subject, int $limit = 0, &$count = 0) {} +function preg_filter($regex, $replace, $subject, int $limit = 0, &$count = null) {} /** * @param string|array $regex @@ -29,7 +29,7 @@ function preg_filter($regex, $replace, $subject, int $limit = 0, &$count = 0) {} * * TODO: $callback should be `callable` */ -function preg_replace_callback($regex, $callback, $subject, int $limit = 0, &$count = 0) {} +function preg_replace_callback($regex, $callback, $subject, int $limit = 0, &$count = null) {} /** * @param array $pattern @@ -38,7 +38,7 @@ function preg_replace_callback($regex, $callback, $subject, int $limit = 0, &$co * @param int $count * @return string|array|null */ -function preg_replace_callback_array(array $pattern, $subject, int $limit = 0, &$count = 0) {} +function preg_replace_callback_array(array $pattern, $subject, int $limit = 0, &$count = null) {} /** * @return array|false From 69e017fc5f5070f356b220746125e5fb69c85636 Mon Sep 17 00:00:00 2001 From: Stephen Reay Date: Sun, 11 Aug 2019 16:46:49 +0700 Subject: [PATCH 5/5] More fixes to PCRE stubs --- ext/pcre/php_pcre.stub.php | 19 ++++++++----------- ext/pcre/php_pcre_arginfo.h | 16 +++++++++------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ext/pcre/php_pcre.stub.php b/ext/pcre/php_pcre.stub.php index 46fb9274eb0c1..f4730f1b6074b 100644 --- a/ext/pcre/php_pcre.stub.php +++ b/ext/pcre/php_pcre.stub.php @@ -10,17 +10,17 @@ function preg_match_all(string $pattern, string $subject, &$subpatterns = null, * @param string|array $regex * @param string|array $replace * @param string|array $subject - * @return string|array|null + * @return string|array|null|false */ -function preg_replace($regex, $replace, $subject, int $limit = 0, &$count = null) {} +function preg_replace($regex, $replace, $subject, int $limit = -1, &$count = null) {} /** * @param string|array $regex * @param string|array $replace * @param string|array $subject - * @return string|array|null + * @return string|array|null|false */ -function preg_filter($regex, $replace, $subject, int $limit = 0, &$count = null) {} +function preg_filter($regex, $replace, $subject, int $limit = -1, &$count = null) {} /** * @param string|array $regex @@ -29,24 +29,21 @@ function preg_filter($regex, $replace, $subject, int $limit = 0, &$count = null) * * TODO: $callback should be `callable` */ -function preg_replace_callback($regex, $callback, $subject, int $limit = 0, &$count = null) {} +function preg_replace_callback($regex, $callback, $subject, int $limit = -1, &$count = null, int $flags = 0) {} /** - * @param array $pattern * @param string|array $subject - * @param int $limit - * @param int $count * @return string|array|null */ -function preg_replace_callback_array(array $pattern, $subject, int $limit = 0, &$count = null) {} +function preg_replace_callback_array(array $pattern, $subject, int $limit = -1, &$count = null, int $flags = 0) {} /** * @return array|false */ -function preg_split(string $pattern, string $subject, int $limit = 0, int $flags = 0) {} +function preg_split(string $pattern, string $subject, int $limit = -1, int $flags = 0) {} -function preg_quote(string $str, string $delim_char): string {} +function preg_quote(string $str, ?string $delim_char = null): string {} /** @return array|false */ function preg_grep(string $regex, array $input, int $flags = 0) {} diff --git a/ext/pcre/php_pcre_arginfo.h b/ext/pcre/php_pcre_arginfo.h index 965cb10f43b18..aff71e652a56f 100644 --- a/ext/pcre/php_pcre_arginfo.h +++ b/ext/pcre/php_pcre_arginfo.h @@ -1,9 +1,9 @@ /* This is a generated file, edit the .stub.php file instead. */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_match, 0, 0, 3) +ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_match, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(1, subpatterns, IS_ARRAY, 0) + ZEND_ARG_INFO(1, subpatterns) ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -15,7 +15,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace, 0, 0, 3) ZEND_ARG_INFO(0, replace) ZEND_ARG_INFO(0, subject) ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(1, count, IS_LONG, 0) + ZEND_ARG_INFO(1, count) ZEND_END_ARG_INFO() #define arginfo_preg_filter arginfo_preg_replace @@ -25,14 +25,16 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback, 0, 0, 3) ZEND_ARG_INFO(0, callback) ZEND_ARG_INFO(0, subject) ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(1, count, IS_LONG, 0) + ZEND_ARG_INFO(1, count) + ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback_array, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, pattern, IS_ARRAY, 0) ZEND_ARG_INFO(0, subject) ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(1, count, IS_LONG, 0) + ZEND_ARG_INFO(1, count) + ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_split, 0, 0, 2) @@ -42,9 +44,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_split, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_preg_quote, 0, 2, IS_STRING, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_preg_quote, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, delim_char, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, delim_char, IS_STRING, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_grep, 0, 0, 2)