]> granicus.if.org Git - php/commitdiff
Add stubs for PCRE extension
authorStephen Reay <stephen.reay@me.com>
Sat, 10 Aug 2019 12:52:50 +0000 (19:52 +0700)
committerNikita Popov <nikita.ppv@gmail.com>
Sun, 11 Aug 2019 10:46:42 +0000 (12:46 +0200)
Closes GH-4501.

ext/pcre/php_pcre.c
ext/pcre/php_pcre.stub.php [new file with mode: 0644]
ext/pcre/php_pcre_arginfo.h [new file with mode: 0644]
sapi/cli/tests/006.phpt

index 6c265df48507fed9462ef1c6b1d3c92dea9d41c1..6002eedc782e887bd5230b86ed3c3704dc712d0d 100644 (file)
@@ -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,70 +2911,6 @@ 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()
-/* }}} */
-
 static const zend_function_entry pcre_functions[] = {
        PHP_FE(preg_match,                                      arginfo_preg_match)
        PHP_FE(preg_match_all,                          arginfo_preg_match_all)
diff --git a/ext/pcre/php_pcre.stub.php b/ext/pcre/php_pcre.stub.php
new file mode 100644 (file)
index 0000000..f4730f1
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+/** @return int|false */
+function preg_match(string $pattern, string $subject, &$subpatterns = null, int $flags = 0, int $offset = 0) {}
+
+/** @return int|false */
+function preg_match_all(string $pattern, string $subject, &$subpatterns = null, int $flags = 0, int $offset = 0) {}
+
+/**
+ * @param string|array $regex
+ * @param string|array $replace
+ * @param string|array $subject
+ * @return string|array|null|false
+ */
+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|false
+ */
+function preg_filter($regex, $replace, $subject, int $limit = -1, &$count = null) {}
+
+/**
+ * @param string|array $regex
+ * @param string|array $subject
+ * @return string|array|null
+ *
+ * TODO: $callback should be `callable`
+ */
+function preg_replace_callback($regex, $callback, $subject, int $limit = -1, &$count = null, int $flags = 0) {}
+
+/**
+ * @param string|array $subject
+ * @return string|array|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 = -1, int $flags = 0) {}
+
+
+function preg_quote(string $str, ?string $delim_char = null): string {}
+
+/** @return array|false */
+function preg_grep(string $regex, array $input, int $flags = 0) {}
+
+
+function preg_last_error(): int {}
diff --git a/ext/pcre/php_pcre_arginfo.h b/ext/pcre/php_pcre_arginfo.h
new file mode 100644 (file)
index 0000000..aff71e6
--- /dev/null
@@ -0,0 +1,59 @@
+/* This is a generated file, edit the .stub.php file instead. */
+
+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_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()
+
+#define arginfo_preg_match_all arginfo_preg_match
+
+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_TYPE_INFO(0, limit, IS_LONG, 0)
+       ZEND_ARG_INFO(1, count)
+ZEND_END_ARG_INFO()
+
+#define arginfo_preg_filter arginfo_preg_replace
+
+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_TYPE_INFO(0, limit, 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_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)
+       ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0)
+       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, 1, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, str, 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)
+       ZEND_ARG_TYPE_INFO(0, regex, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, input, IS_ARRAY, 0)
+       ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_preg_last_error, 0, 0, IS_LONG, 0)
+ZEND_END_ARG_INFO()
index 54d1a96a880d76988cdd81e08399b44c8b6448c4..f0eb1e7793c20e47490bc16ddbb5a8aa8efed92d 100644 (file)
@@ -68,21 +68,21 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
     Function [ <internal:pcre> function preg_match ] {
 
       - Parameters [5] {
-        Parameter #0 [ <required> $pattern ]
-        Parameter #1 [ <required> $subject ]
+        Parameter #0 [ <required> string $pattern ]
+        Parameter #1 [ <required> string $subject ]
         Parameter #2 [ <optional> &$subpatterns ]
-        Parameter #3 [ <optional> $flags ]
-        Parameter #4 [ <optional> $offset ]
+        Parameter #3 [ <optional> int $flags ]
+        Parameter #4 [ <optional> int $offset ]
       }
     }
     Function [ <internal:pcre> function preg_match_all ] {
 
       - Parameters [5] {
-        Parameter #0 [ <required> $pattern ]
-        Parameter #1 [ <required> $subject ]
+        Parameter #0 [ <required> string $pattern ]
+        Parameter #1 [ <required> string $subject ]
         Parameter #2 [ <optional> &$subpatterns ]
-        Parameter #3 [ <optional> $flags ]
-        Parameter #4 [ <optional> $offset ]
+        Parameter #3 [ <optional> int $flags ]
+        Parameter #4 [ <optional> int $offset ]
       }
     }
     Function [ <internal:pcre> function preg_replace ] {
@@ -91,7 +91,7 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
         Parameter #0 [ <required> $regex ]
         Parameter #1 [ <required> $replace ]
         Parameter #2 [ <required> $subject ]
-        Parameter #3 [ <optional> $limit ]
+        Parameter #3 [ <optional> int $limit ]
         Parameter #4 [ <optional> &$count ]
       }
     }
@@ -101,19 +101,19 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
         Parameter #0 [ <required> $regex ]
         Parameter #1 [ <required> $callback ]
         Parameter #2 [ <required> $subject ]
-        Parameter #3 [ <optional> $limit ]
+        Parameter #3 [ <optional> int $limit ]
         Parameter #4 [ <optional> &$count ]
-        Parameter #5 [ <optional> $flags ]
+        Parameter #5 [ <optional> int $flags ]
       }
     }
     Function [ <internal:pcre> function preg_replace_callback_array ] {
 
       - Parameters [5] {
-        Parameter #0 [ <required> $pattern ]
+        Parameter #0 [ <required> array $pattern ]
         Parameter #1 [ <required> $subject ]
-        Parameter #2 [ <optional> $limit ]
+        Parameter #2 [ <optional> int $limit ]
         Parameter #3 [ <optional> &$count ]
-        Parameter #4 [ <optional> $flags ]
+        Parameter #4 [ <optional> int $flags ]
       }
     }
     Function [ <internal:pcre> function preg_filter ] {
@@ -122,38 +122,40 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
         Parameter #0 [ <required> $regex ]
         Parameter #1 [ <required> $replace ]
         Parameter #2 [ <required> $subject ]
-        Parameter #3 [ <optional> $limit ]
+        Parameter #3 [ <optional> int $limit ]
         Parameter #4 [ <optional> &$count ]
       }
     }
     Function [ <internal:pcre> function preg_split ] {
 
       - Parameters [4] {
-        Parameter #0 [ <required> $pattern ]
-        Parameter #1 [ <required> $subject ]
-        Parameter #2 [ <optional> $limit ]
-        Parameter #3 [ <optional> $flags ]
+        Parameter #0 [ <required> string $pattern ]
+        Parameter #1 [ <required> string $subject ]
+        Parameter #2 [ <optional> int $limit ]
+        Parameter #3 [ <optional> int $flags ]
       }
     }
     Function [ <internal:pcre> function preg_quote ] {
 
       - Parameters [2] {
-        Parameter #0 [ <required> $str ]
-        Parameter #1 [ <optional> $delim_char ]
+        Parameter #0 [ <required> string $str ]
+        Parameter #1 [ <optional> string or NULL $delim_char ]
       }
+      - Return [ string ]
     }
     Function [ <internal:pcre> function preg_grep ] {
 
       - Parameters [3] {
-        Parameter #0 [ <required> $regex ]
-        Parameter #1 [ <required> $input ]
-        Parameter #2 [ <optional> $flags ]
+        Parameter #0 [ <required> string $regex ]
+        Parameter #1 [ <required> array $input ]
+        Parameter #2 [ <optional> int $flags ]
       }
     }
     Function [ <internal:pcre> function preg_last_error ] {
 
       - Parameters [0] {
       }
+      - Return [ int ]
     }
   }
 }