Skip to content

Commit 6e130dd

Browse files
committed
Add frameless handlers for strstr
1 parent 6ead0ad commit 6e130dd

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

Zend/zend_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,5 +649,7 @@ extern ZEND_FRAMELESS_FUNCTION(strpos, 2);
649649
extern ZEND_FRAMELESS_FUNCTION(strpos, 3);
650650
extern ZEND_FRAMELESS_FUNCTION(substr, 2);
651651
extern ZEND_FRAMELESS_FUNCTION(substr, 3);
652+
extern ZEND_FRAMELESS_FUNCTION(strstr, 2);
653+
extern ZEND_FRAMELESS_FUNCTION(strstr, 3);
652654

653655
#endif /* ZEND_STRING_H */

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,8 @@ function stristr(string $haystack, string $needle, bool $before_needle = false):
23792379
/**
23802380
* @compile-time-eval
23812381
* @refcount 1
2382+
* @frameless-function {"arity": 2}
2383+
* @frameless-function {"arity": 3}
23822384
*/
23832385
function strstr(string $haystack, string $needle, bool $before_needle = false): string|false {}
23842386

ext/standard/basic_functions_arginfo.h

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/string.c

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,20 +1715,10 @@ PHP_FUNCTION(stristr)
17151715
}
17161716
/* }}} */
17171717

1718-
/* {{{ Finds first occurrence of a string within another */
1719-
PHP_FUNCTION(strstr)
1718+
static inline void _zend_strstr(zval *return_value, zend_string *haystack, zend_string *needle, bool part)
17201719
{
1721-
zend_string *haystack, *needle;
17221720
const char *found = NULL;
17231721
zend_long found_offset;
1724-
bool part = 0;
1725-
1726-
ZEND_PARSE_PARAMETERS_START(2, 3)
1727-
Z_PARAM_STR(haystack)
1728-
Z_PARAM_STR(needle)
1729-
Z_PARAM_OPTIONAL
1730-
Z_PARAM_BOOL(part)
1731-
ZEND_PARSE_PARAMETERS_END();
17321722

17331723
found = php_memnstr(ZSTR_VAL(haystack), ZSTR_VAL(needle), ZSTR_LEN(needle), ZSTR_VAL(haystack) + ZSTR_LEN(haystack));
17341724

@@ -1741,8 +1731,56 @@ PHP_FUNCTION(strstr)
17411731
}
17421732
RETURN_STRINGL(found, ZSTR_LEN(haystack) - found_offset);
17431733
}
1734+
1735+
/* {{{ Finds first occurrence of a string within another */
1736+
PHP_FUNCTION(strstr)
1737+
{
1738+
zend_string *haystack, *needle;
1739+
bool part = 0;
1740+
1741+
ZEND_PARSE_PARAMETERS_START(2, 3)
1742+
Z_PARAM_STR(haystack)
1743+
Z_PARAM_STR(needle)
1744+
Z_PARAM_OPTIONAL
1745+
Z_PARAM_BOOL(part)
1746+
ZEND_PARSE_PARAMETERS_END();
1747+
1748+
_zend_strstr(return_value, haystack, needle, part);
1749+
}
17441750
/* }}} */
17451751

1752+
ZEND_FRAMELESS_FUNCTION(strstr, 2)
1753+
{
1754+
zval haystack_tmp, needle_tmp;
1755+
zend_string *haystack, *needle;
1756+
1757+
Z_FLF_PARAM_STR(1, haystack, haystack_tmp);
1758+
Z_FLF_PARAM_STR(2, needle, needle_tmp);
1759+
1760+
_zend_strstr(return_value, haystack, needle, /* part */ false);
1761+
1762+
flf_clean:
1763+
Z_FLF_PARAM_FREE_STR(1, haystack_tmp);
1764+
Z_FLF_PARAM_FREE_STR(2, needle_tmp);
1765+
}
1766+
1767+
ZEND_FRAMELESS_FUNCTION(strstr, 3)
1768+
{
1769+
zval haystack_tmp, needle_tmp;
1770+
zend_string *haystack, *needle;
1771+
bool part;
1772+
1773+
Z_FLF_PARAM_STR(1, haystack, haystack_tmp);
1774+
Z_FLF_PARAM_STR(2, needle, needle_tmp);
1775+
Z_FLF_PARAM_BOOL(3, part);
1776+
1777+
_zend_strstr(return_value, haystack, needle, part);
1778+
1779+
flf_clean:
1780+
Z_FLF_PARAM_FREE_STR(1, haystack_tmp);
1781+
Z_FLF_PARAM_FREE_STR(2, needle_tmp);
1782+
}
1783+
17461784
/* {{{ Checks if a string contains another */
17471785
PHP_FUNCTION(str_contains)
17481786
{

0 commit comments

Comments
 (0)