Skip to content

Commit 66b750d

Browse files
stephenreaynikic
authored andcommitted
Add stubs for PCRE extension
Closes GH-4501.
1 parent 31d7f97 commit 66b750d

File tree

4 files changed

+138
-88
lines changed

4 files changed

+138
-88
lines changed

ext/pcre/php_pcre.c

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "php_ini.h"
2121
#include "php_globals.h"
2222
#include "php_pcre.h"
23+
#include "php_pcre_arginfo.h"
2324
#include "ext/standard/info.h"
2425
#include "ext/standard/basic_functions.h"
2526
#include "zend_smart_str.h"
@@ -2910,70 +2911,6 @@ static PHP_FUNCTION(preg_last_error)
29102911

29112912
/* {{{ module definition structures */
29122913

2913-
/* {{{ arginfo */
2914-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_match, 0, 0, 2)
2915-
ZEND_ARG_INFO(0, pattern)
2916-
ZEND_ARG_INFO(0, subject)
2917-
ZEND_ARG_INFO(1, subpatterns) /* array */
2918-
ZEND_ARG_INFO(0, flags)
2919-
ZEND_ARG_INFO(0, offset)
2920-
ZEND_END_ARG_INFO()
2921-
2922-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_match_all, 0, 0, 2)
2923-
ZEND_ARG_INFO(0, pattern)
2924-
ZEND_ARG_INFO(0, subject)
2925-
ZEND_ARG_INFO(1, subpatterns) /* array */
2926-
ZEND_ARG_INFO(0, flags)
2927-
ZEND_ARG_INFO(0, offset)
2928-
ZEND_END_ARG_INFO()
2929-
2930-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace, 0, 0, 3)
2931-
ZEND_ARG_INFO(0, regex)
2932-
ZEND_ARG_INFO(0, replace)
2933-
ZEND_ARG_INFO(0, subject)
2934-
ZEND_ARG_INFO(0, limit)
2935-
ZEND_ARG_INFO(1, count)
2936-
ZEND_END_ARG_INFO()
2937-
2938-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback, 0, 0, 3)
2939-
ZEND_ARG_INFO(0, regex)
2940-
ZEND_ARG_INFO(0, callback)
2941-
ZEND_ARG_INFO(0, subject)
2942-
ZEND_ARG_INFO(0, limit)
2943-
ZEND_ARG_INFO(1, count)
2944-
ZEND_ARG_INFO(0, flags)
2945-
ZEND_END_ARG_INFO()
2946-
2947-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback_array, 0, 0, 2)
2948-
ZEND_ARG_INFO(0, pattern)
2949-
ZEND_ARG_INFO(0, subject)
2950-
ZEND_ARG_INFO(0, limit)
2951-
ZEND_ARG_INFO(1, count)
2952-
ZEND_ARG_INFO(0, flags)
2953-
ZEND_END_ARG_INFO()
2954-
2955-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_split, 0, 0, 2)
2956-
ZEND_ARG_INFO(0, pattern)
2957-
ZEND_ARG_INFO(0, subject)
2958-
ZEND_ARG_INFO(0, limit)
2959-
ZEND_ARG_INFO(0, flags)
2960-
ZEND_END_ARG_INFO()
2961-
2962-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_quote, 0, 0, 1)
2963-
ZEND_ARG_INFO(0, str)
2964-
ZEND_ARG_INFO(0, delim_char)
2965-
ZEND_END_ARG_INFO()
2966-
2967-
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_grep, 0, 0, 2)
2968-
ZEND_ARG_INFO(0, regex)
2969-
ZEND_ARG_INFO(0, input) /* array */
2970-
ZEND_ARG_INFO(0, flags)
2971-
ZEND_END_ARG_INFO()
2972-
2973-
ZEND_BEGIN_ARG_INFO(arginfo_preg_last_error, 0)
2974-
ZEND_END_ARG_INFO()
2975-
/* }}} */
2976-
29772914
static const zend_function_entry pcre_functions[] = {
29782915
PHP_FE(preg_match, arginfo_preg_match)
29792916
PHP_FE(preg_match_all, arginfo_preg_match_all)

ext/pcre/php_pcre.stub.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/** @return int|false */
4+
function preg_match(string $pattern, string $subject, &$subpatterns = null, int $flags = 0, int $offset = 0) {}
5+
6+
/** @return int|false */
7+
function preg_match_all(string $pattern, string $subject, &$subpatterns = null, int $flags = 0, int $offset = 0) {}
8+
9+
/**
10+
* @param string|array $regex
11+
* @param string|array $replace
12+
* @param string|array $subject
13+
* @return string|array|null|false
14+
*/
15+
function preg_replace($regex, $replace, $subject, int $limit = -1, &$count = null) {}
16+
17+
/**
18+
* @param string|array $regex
19+
* @param string|array $replace
20+
* @param string|array $subject
21+
* @return string|array|null|false
22+
*/
23+
function preg_filter($regex, $replace, $subject, int $limit = -1, &$count = null) {}
24+
25+
/**
26+
* @param string|array $regex
27+
* @param string|array $subject
28+
* @return string|array|null
29+
*
30+
* TODO: $callback should be `callable`
31+
*/
32+
function preg_replace_callback($regex, $callback, $subject, int $limit = -1, &$count = null, int $flags = 0) {}
33+
34+
/**
35+
* @param string|array $subject
36+
* @return string|array|null
37+
*/
38+
function preg_replace_callback_array(array $pattern, $subject, int $limit = -1, &$count = null, int $flags = 0) {}
39+
40+
/**
41+
* @return array|false
42+
*/
43+
function preg_split(string $pattern, string $subject, int $limit = -1, int $flags = 0) {}
44+
45+
46+
function preg_quote(string $str, ?string $delim_char = null): string {}
47+
48+
/** @return array|false */
49+
function preg_grep(string $regex, array $input, int $flags = 0) {}
50+
51+
52+
function preg_last_error(): int {}

ext/pcre/php_pcre_arginfo.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* This is a generated file, edit the .stub.php file instead. */
2+
3+
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_match, 0, 0, 2)
4+
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
5+
ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0)
6+
ZEND_ARG_INFO(1, subpatterns)
7+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
8+
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
9+
ZEND_END_ARG_INFO()
10+
11+
#define arginfo_preg_match_all arginfo_preg_match
12+
13+
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace, 0, 0, 3)
14+
ZEND_ARG_INFO(0, regex)
15+
ZEND_ARG_INFO(0, replace)
16+
ZEND_ARG_INFO(0, subject)
17+
ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0)
18+
ZEND_ARG_INFO(1, count)
19+
ZEND_END_ARG_INFO()
20+
21+
#define arginfo_preg_filter arginfo_preg_replace
22+
23+
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback, 0, 0, 3)
24+
ZEND_ARG_INFO(0, regex)
25+
ZEND_ARG_INFO(0, callback)
26+
ZEND_ARG_INFO(0, subject)
27+
ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0)
28+
ZEND_ARG_INFO(1, count)
29+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
30+
ZEND_END_ARG_INFO()
31+
32+
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_replace_callback_array, 0, 0, 2)
33+
ZEND_ARG_TYPE_INFO(0, pattern, IS_ARRAY, 0)
34+
ZEND_ARG_INFO(0, subject)
35+
ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0)
36+
ZEND_ARG_INFO(1, count)
37+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
38+
ZEND_END_ARG_INFO()
39+
40+
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_split, 0, 0, 2)
41+
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
42+
ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0)
43+
ZEND_ARG_TYPE_INFO(0, limit, IS_LONG, 0)
44+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
45+
ZEND_END_ARG_INFO()
46+
47+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_preg_quote, 0, 1, IS_STRING, 0)
48+
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
49+
ZEND_ARG_TYPE_INFO(0, delim_char, IS_STRING, 1)
50+
ZEND_END_ARG_INFO()
51+
52+
ZEND_BEGIN_ARG_INFO_EX(arginfo_preg_grep, 0, 0, 2)
53+
ZEND_ARG_TYPE_INFO(0, regex, IS_STRING, 0)
54+
ZEND_ARG_TYPE_INFO(0, input, IS_ARRAY, 0)
55+
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
56+
ZEND_END_ARG_INFO()
57+
58+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_preg_last_error, 0, 0, IS_LONG, 0)
59+
ZEND_END_ARG_INFO()

sapi/cli/tests/006.phpt

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
6868
Function [ <internal:pcre> function preg_match ] {
6969

7070
- Parameters [5] {
71-
Parameter #0 [ <required> $pattern ]
72-
Parameter #1 [ <required> $subject ]
71+
Parameter #0 [ <required> string $pattern ]
72+
Parameter #1 [ <required> string $subject ]
7373
Parameter #2 [ <optional> &$subpatterns ]
74-
Parameter #3 [ <optional> $flags ]
75-
Parameter #4 [ <optional> $offset ]
74+
Parameter #3 [ <optional> int $flags ]
75+
Parameter #4 [ <optional> int $offset ]
7676
}
7777
}
7878
Function [ <internal:pcre> function preg_match_all ] {
7979

8080
- Parameters [5] {
81-
Parameter #0 [ <required> $pattern ]
82-
Parameter #1 [ <required> $subject ]
81+
Parameter #0 [ <required> string $pattern ]
82+
Parameter #1 [ <required> string $subject ]
8383
Parameter #2 [ <optional> &$subpatterns ]
84-
Parameter #3 [ <optional> $flags ]
85-
Parameter #4 [ <optional> $offset ]
84+
Parameter #3 [ <optional> int $flags ]
85+
Parameter #4 [ <optional> int $offset ]
8686
}
8787
}
8888
Function [ <internal:pcre> function preg_replace ] {
@@ -91,7 +91,7 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
9191
Parameter #0 [ <required> $regex ]
9292
Parameter #1 [ <required> $replace ]
9393
Parameter #2 [ <required> $subject ]
94-
Parameter #3 [ <optional> $limit ]
94+
Parameter #3 [ <optional> int $limit ]
9595
Parameter #4 [ <optional> &$count ]
9696
}
9797
}
@@ -101,19 +101,19 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
101101
Parameter #0 [ <required> $regex ]
102102
Parameter #1 [ <required> $callback ]
103103
Parameter #2 [ <required> $subject ]
104-
Parameter #3 [ <optional> $limit ]
104+
Parameter #3 [ <optional> int $limit ]
105105
Parameter #4 [ <optional> &$count ]
106-
Parameter #5 [ <optional> $flags ]
106+
Parameter #5 [ <optional> int $flags ]
107107
}
108108
}
109109
Function [ <internal:pcre> function preg_replace_callback_array ] {
110110

111111
- Parameters [5] {
112-
Parameter #0 [ <required> $pattern ]
112+
Parameter #0 [ <required> array $pattern ]
113113
Parameter #1 [ <required> $subject ]
114-
Parameter #2 [ <optional> $limit ]
114+
Parameter #2 [ <optional> int $limit ]
115115
Parameter #3 [ <optional> &$count ]
116-
Parameter #4 [ <optional> $flags ]
116+
Parameter #4 [ <optional> int $flags ]
117117
}
118118
}
119119
Function [ <internal:pcre> function preg_filter ] {
@@ -122,38 +122,40 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] {
122122
Parameter #0 [ <required> $regex ]
123123
Parameter #1 [ <required> $replace ]
124124
Parameter #2 [ <required> $subject ]
125-
Parameter #3 [ <optional> $limit ]
125+
Parameter #3 [ <optional> int $limit ]
126126
Parameter #4 [ <optional> &$count ]
127127
}
128128
}
129129
Function [ <internal:pcre> function preg_split ] {
130130

131131
- Parameters [4] {
132-
Parameter #0 [ <required> $pattern ]
133-
Parameter #1 [ <required> $subject ]
134-
Parameter #2 [ <optional> $limit ]
135-
Parameter #3 [ <optional> $flags ]
132+
Parameter #0 [ <required> string $pattern ]
133+
Parameter #1 [ <required> string $subject ]
134+
Parameter #2 [ <optional> int $limit ]
135+
Parameter #3 [ <optional> int $flags ]
136136
}
137137
}
138138
Function [ <internal:pcre> function preg_quote ] {
139139

140140
- Parameters [2] {
141-
Parameter #0 [ <required> $str ]
142-
Parameter #1 [ <optional> $delim_char ]
141+
Parameter #0 [ <required> string $str ]
142+
Parameter #1 [ <optional> string or NULL $delim_char ]
143143
}
144+
- Return [ string ]
144145
}
145146
Function [ <internal:pcre> function preg_grep ] {
146147

147148
- Parameters [3] {
148-
Parameter #0 [ <required> $regex ]
149-
Parameter #1 [ <required> $input ]
150-
Parameter #2 [ <optional> $flags ]
149+
Parameter #0 [ <required> string $regex ]
150+
Parameter #1 [ <required> array $input ]
151+
Parameter #2 [ <optional> int $flags ]
151152
}
152153
}
153154
Function [ <internal:pcre> function preg_last_error ] {
154155

155156
- Parameters [0] {
156157
}
158+
- Return [ int ]
157159
}
158160
}
159161
}

0 commit comments

Comments
 (0)