size_t charset_len = 0;
zend_string *str;
zend_long offset, length = 0;
+ zend_bool len_is_null = 1;
php_iconv_err_t err;
smart_str retval = {0};
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|ls",
- &str, &offset, &length,
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l!s",
+ &str, &offset, &length, &len_is_null,
&charset, &charset_len) == FAILURE) {
return;
}
RETURN_FALSE;
}
- if (ZEND_NUM_ARGS() < 3) {
+ if (len_is_null) {
length = ZSTR_LEN(str);
}
function iconv_strlen(string $str, string $charset = UNKNOWN) {}
/** @return string|false */
-function iconv_substr(string $str, int $offset, int $length = UNKNOWN, string $charset = UNKNOWN) {}
+function iconv_substr(string $str, int $offset, ?int $length = null, string $charset = UNKNOWN) {}
/** @return int|false */
function iconv_strpos(string $haystack, string $needle, int $offset = 0, string $charset = UNKNOWN) {}
ZEND_BEGIN_ARG_INFO_EX(arginfo_iconv_substr, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
- ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
ZEND_ARG_TYPE_INFO(0, charset, IS_STRING, 0)
ZEND_END_ARG_INFO()
bar("This is a test", 100000);
bar("This is a test", 0, 100000);
bar("This is a test", -3);
+bar("This is a test", -3, null);
bar("This is a test", 0, -9);
bar("This is a test", 0, -100000);
bar("This is a test", -9, -100000);
string(14) "This is a test"
string(3) "est"
string(3) "est"
+string(3) "est"
+string(3) "est"
string(5) "This "
string(5) "This "
bool(false)
function chunk_split(string $str, int $chunklen = 76, string $ending = "\r\n"): string {}
/** @return string|false */
-function substr(string $str, int $start, int $length = UNKNOWN) {}
+function substr(string $str, int $start, ?int $length = null) {}
/**
* @param mixed $str
function strnatcasecmp(string $s1, string $s2): int {}
/** @return int|false */
-function substr_count(string $haystack, string $needle, int $offset = 0, int $length = UNKNOWN) {}
+function substr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null) {}
function str_pad(string $input, int $pad_length, string $pad_string = " ", int $pad_type = STR_PAD_RIGHT): string {}
function strpbrk(string $haystack, string $char_list) {}
/** @return int|false */
-function substr_compare(string $main_str, string $str, int $offset, int $length = UNKNOWN, bool $case_insensitivity = false) {}
+function substr_compare(string $main_str, string $str, int $offset, ?int $length = null, bool $case_insensitivity = false) {}
function utf8_encode(string $data): string {}
ZEND_BEGIN_ARG_INFO_EX(arginfo_substr, 0, 0, 2)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0)
- ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_substr_replace, 0, 0, 3)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
- ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_str_pad, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, main_str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
- ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0)
+ ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
ZEND_ARG_TYPE_INFO(0, case_insensitivity, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
{
zend_string *str;
zend_long l = 0, f;
- int argc = ZEND_NUM_ARGS();
+ zend_bool len_is_null = 1;
ZEND_PARSE_PARAMETERS_START(2, 3)
Z_PARAM_STR(str)
Z_PARAM_LONG(f)
Z_PARAM_OPTIONAL
- Z_PARAM_LONG(l)
+ Z_PARAM_LONG_OR_NULL(l, len_is_null)
ZEND_PARSE_PARAMETERS_END();
if (f > (zend_long)ZSTR_LEN(str)) {
} else {
f = (zend_long)ZSTR_LEN(str) + f;
}
- if (argc > 2) {
+ if (!len_is_null) {
if (l < 0) {
/* if "length" position is negative, set it to the length
* needed to stop that many chars from the end of the string
} else {
goto truncate_len;
}
- } else if (argc > 2) {
+ } else if (!len_is_null) {
if (l < 0) {
/* if "length" position is negative, set it to the length
* needed to stop that many chars from the end of the string
{
char *haystack, *needle;
zend_long offset = 0, length = 0;
- int ac = ZEND_NUM_ARGS();
+ zend_bool length_is_null = 1;
zend_long count = 0;
size_t haystack_len, needle_len;
const char *p, *endp;
Z_PARAM_STRING(needle, needle_len)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(offset)
- Z_PARAM_LONG(length)
+ Z_PARAM_LONG_OR_NULL(length, length_is_null)
ZEND_PARSE_PARAMETERS_END();
if (needle_len == 0) {
}
p += offset;
- if (ac == 4) {
+ if (!length_is_null) {
if (length < 0) {
length += (haystack_len - offset);
<?php
var_dump(substr_compare("abcde", "df", -2) < 0);
+var_dump(substr_compare("abcde", "df", -2, null) < 0);
var_dump(substr_compare("abcde", "bc", 1, 2));
var_dump(substr_compare("abcde", "bcg", 1, 2));
var_dump(substr_compare("abcde", "BC", 1, 2, true));
?>
--EXPECTF--
bool(true)
+bool(true)
int(0)
int(0)
int(0)
$a = str_repeat("abcacbabca", 100);
var_dump(substr_count($a, "bca"));
var_dump(substr_count($a, "bca", 200));
+var_dump(substr_count($a, "bca", 200, null));
var_dump(substr_count($a, "bca", 200, 50));
var_dump(substr_count($a, "bca", -200));
+var_dump(substr_count($a, "bca", -200, null));
var_dump(substr_count($a, "bca", -200, 50));
var_dump(substr_count($a, "bca", -200, -50));
int(100)
int(200)
int(160)
+int(160)
int(10)
int(40)
+int(40)
int(10)
int(30)
Done