Skip to content

Add stubs for PCRE extension #4501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions ext/pcre/php_pcre.stub.php
Original file line number Diff line number Diff line change
@@ -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 {}
59 changes: 59 additions & 0 deletions ext/pcre/php_pcre_arginfo.h
Original file line number Diff line number Diff line change
@@ -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()