diff options
Diffstat (limited to 'ext/standard')
-rwxr-xr-x | ext/standard/basic_functions.stub.php | 12 | ||||
-rwxr-xr-x | ext/standard/basic_functions_arginfo.h | 10 | ||||
-rw-r--r-- | ext/standard/head.c | 37 | ||||
-rw-r--r-- | ext/standard/string.c | 62 |
4 files changed, 51 insertions, 70 deletions
diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 8e3996e072..281d8167b8 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -502,11 +502,9 @@ function header(string $string, bool $replace = true, int $http_response_code = function header_remove(?string $name = null): void {} -/** @param array|int $expires_or_options */ -function setrawcookie(string $name, string $value = '', $expires_or_options = 0, string $path = '', string $domain = '', bool $secure = false, bool $httponly = false): bool {} +function setrawcookie(string $name, string $value = '', array|int $expires_or_options = 0, string $path = '', string $domain = '', bool $secure = false, bool $httponly = false): bool {} -/** @param array|int $expires_or_options */ -function setcookie(string $name, string $value = '', $expires_or_options = 0, string $path = '', string $domain = '', bool $secure = false, bool $httponly = false): bool {} +function setcookie(string $name, string $value = '', array|int $expires_or_options = 0, string $path = '', string $domain = '', bool $secure = false, bool $httponly = false): bool {} function http_response_code(int $response_code = 0): int|bool {} @@ -612,11 +610,7 @@ function chunk_split(string $str, int $chunklen = 76, string $ending = "\r\n"): function substr(string $str, int $start, ?int $length = null): string|false {} -/** - * @param array|int $start - * @param array|int|null $length - */ -function substr_replace(array|string $str, string|array $replace, $start, $length = null): string|array|false {} +function substr_replace(array|string $str, array|string $replace, array|int $start, array|int|null $length = null): string|array|false {} function quotemeta(string $str): string {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 5943429517..5097ca53fc 100755 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 251fc9f272492ab76c4a1a1dabcd768269cf1bde */ + * Stub hash: d1bcbdfe71bdc57680abe391d1ef2859538615c2 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) @@ -746,7 +746,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_setrawcookie, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, value, IS_STRING, 0, "\'\'") - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, expires_or_options, "0") + ZEND_ARG_TYPE_MASK(0, expires_or_options, MAY_BE_ARRAY|MAY_BE_LONG, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 0, "\'\'") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 0, "\'\'") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, secure, _IS_BOOL, 0, "false") @@ -935,9 +935,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_replace, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_MASK(0, str, MAY_BE_ARRAY|MAY_BE_STRING, NULL) - ZEND_ARG_TYPE_MASK(0, replace, MAY_BE_STRING|MAY_BE_ARRAY, NULL) - ZEND_ARG_INFO(0, start) - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, length, "null") + ZEND_ARG_TYPE_MASK(0, replace, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_MASK(0, start, MAY_BE_ARRAY|MAY_BE_LONG, NULL) + ZEND_ARG_TYPE_MASK(0, length, MAY_BE_ARRAY|MAY_BE_LONG|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() #define arginfo_quotemeta arginfo_base64_encode diff --git a/ext/standard/head.c b/ext/standard/head.c index 18cb0c4f62..36f64fcb4d 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -192,13 +192,13 @@ PHPAPI zend_result php_setcookie(zend_string *name, zend_string *value, time_t e return result; } -static zend_result php_head_parse_cookie_options_array(zval *options, zend_long *expires, zend_string **path, +static zend_result php_head_parse_cookie_options_array(HashTable *options, zend_long *expires, zend_string **path, zend_string **domain, zend_bool *secure, zend_bool *httponly, zend_string **samesite) { zend_string *key; zval *value; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), key, value) { + ZEND_HASH_FOREACH_STR_KEY_VAL(options, key, value) { if (!key) { zend_value_error("%s(): option array cannot have numeric keys", get_active_function_name()); return FAILURE; @@ -225,36 +225,33 @@ static zend_result php_head_parse_cookie_options_array(zval *options, zend_long static void php_setcookie_common(INTERNAL_FUNCTION_PARAMETERS, bool is_raw) { - /* to handle overloaded function array|int */ - zval *expires_or_options = NULL; - zend_string *name, *value = NULL, *path = NULL, *domain = NULL, *samesite = NULL; + HashTable *options = NULL; zend_long expires = 0; + zend_string *name, *value = NULL, *path = NULL, *domain = NULL, *samesite = NULL; zend_bool secure = 0, httponly = 0; ZEND_PARSE_PARAMETERS_START(1, 7) Z_PARAM_STR(name) Z_PARAM_OPTIONAL Z_PARAM_STR(value) - Z_PARAM_ZVAL(expires_or_options) + Z_PARAM_ARRAY_HT_OR_LONG(options, expires) Z_PARAM_STR(path) Z_PARAM_STR(domain) Z_PARAM_BOOL(secure) Z_PARAM_BOOL(httponly) ZEND_PARSE_PARAMETERS_END(); - if (expires_or_options) { - if (Z_TYPE_P(expires_or_options) == IS_ARRAY) { - if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) { - zend_argument_count_error("%s(): Expects exactly 3 arguments when argument #3 " - "($expires_or_options) is an array", get_active_function_name()); - RETURN_THROWS(); - } - if (FAILURE == php_head_parse_cookie_options_array(expires_or_options, &expires, &path, - &domain, &secure, &httponly, &samesite)) { - goto cleanup; - } - } else { - expires = zval_get_long(expires_or_options); + if (options) { + if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) { + zend_argument_count_error("%s(): Expects exactly 3 arguments when argument #3 " + "($expires_or_options) is an array", get_active_function_name()); + RETURN_THROWS(); + } + + if (FAILURE == php_head_parse_cookie_options_array(options, &expires, &path, + &domain, &secure, &httponly, &samesite) + ) { + goto cleanup; } } @@ -264,7 +261,7 @@ static void php_setcookie_common(INTERNAL_FUNCTION_PARAMETERS, bool is_raw) RETVAL_FALSE; } - if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) { + if (options) { cleanup: if (path) { zend_string_release(path); diff --git a/ext/standard/string.c b/ext/standard/string.c index 9fd7e5f454..b3d357baa8 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2237,8 +2237,11 @@ PHP_FUNCTION(substr_replace) { zend_string *str, *repl_str; HashTable *str_ht, *repl_ht; - zval *from; - zval *len = NULL; + HashTable *from_ht; + zend_long from_long; + HashTable *len_ht = NULL; + zend_long len_long; + zend_bool len_is_null = 1; zend_long l = 0; zend_long f; zend_string *result; @@ -2248,39 +2251,26 @@ PHP_FUNCTION(substr_replace) ZEND_PARSE_PARAMETERS_START(3, 4) Z_PARAM_ARRAY_HT_OR_STR(str_ht, str) Z_PARAM_ARRAY_HT_OR_STR(repl_ht, repl_str) - Z_PARAM_ZVAL(from) + Z_PARAM_ARRAY_HT_OR_LONG(from_ht, from_long) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL_OR_NULL(len) + Z_PARAM_ARRAY_HT_OR_LONG_OR_NULL(len_ht, len_long, len_is_null) ZEND_PARSE_PARAMETERS_END(); - if (Z_TYPE_P(from) != IS_ARRAY) { - convert_to_long_ex(from); - if (EG(exception)) { - RETURN_THROWS(); - } - } - - if (len) { - if (Z_TYPE_P(len) != IS_ARRAY) { - convert_to_long_ex(len); - l = Z_LVAL_P(len); - } - } else { + if (len_is_null) { if (str) { l = ZSTR_LEN(str); } + } else if (!len_ht) { + l = len_long; } if (str) { - if ( - (!len && Z_TYPE_P(from) == IS_ARRAY) || - (len && Z_TYPE_P(from) != Z_TYPE_P(len)) - ) { + if ((len_is_null && from_ht) || (!len_is_null && (from_ht == NULL) != (len_ht == NULL))) { php_error_docref(NULL, E_WARNING, "'start' and 'length' should be of same type - numerical or array "); RETURN_STR_COPY(str); } - if (len && Z_TYPE_P(from) == IS_ARRAY) { - if (zend_hash_num_elements(Z_ARRVAL_P(from)) != zend_hash_num_elements(Z_ARRVAL_P(len))) { + if (!len_is_null && from_ht) { + if (zend_hash_num_elements(from_ht) != zend_hash_num_elements(len_ht)) { php_error_docref(NULL, E_WARNING, "'start' and 'length' should have the same number of elements"); RETURN_STR_COPY(str); } @@ -2288,8 +2278,8 @@ PHP_FUNCTION(substr_replace) } if (str) { - if (Z_TYPE_P(from) != IS_ARRAY) { - f = Z_LVAL_P(from); + if (!from_ht) { + f = from_long; /* if "from" position is negative, count start position from the end * of the string @@ -2364,15 +2354,15 @@ PHP_FUNCTION(substr_replace) zend_string *tmp_orig_str; zend_string *orig_str = zval_get_tmp_string(tmp_str, &tmp_orig_str); - if (Z_TYPE_P(from) == IS_ARRAY) { - while (from_idx < Z_ARRVAL_P(from)->nNumUsed) { - tmp_from = &Z_ARRVAL_P(from)->arData[from_idx].val; + if (from_ht) { + while (from_idx < from_ht->nNumUsed) { + tmp_from = &from_ht->arData[from_idx].val; if (Z_TYPE_P(tmp_from) != IS_UNDEF) { break; } from_idx++; } - if (from_idx < Z_ARRVAL_P(from)->nNumUsed) { + if (from_idx < from_ht->nNumUsed) { f = zval_get_long(tmp_from); if (f < 0) { @@ -2388,7 +2378,7 @@ PHP_FUNCTION(substr_replace) f = 0; } } else { - f = Z_LVAL_P(from); + f = from_long; if (f < 0) { f = (zend_long)ZSTR_LEN(orig_str) + f; if (f < 0) { @@ -2399,22 +2389,22 @@ PHP_FUNCTION(substr_replace) } } - if (len && Z_TYPE_P(len) == IS_ARRAY) { - while (len_idx < Z_ARRVAL_P(len)->nNumUsed) { - tmp_len = &Z_ARRVAL_P(len)->arData[len_idx].val; + if (len_ht) { + while (len_idx < len_ht->nNumUsed) { + tmp_len = &len_ht->arData[len_idx].val; if (Z_TYPE_P(tmp_len) != IS_UNDEF) { break; } len_idx++; } - if (len_idx < Z_ARRVAL_P(len)->nNumUsed) { + if (len_idx < len_ht->nNumUsed) { l = zval_get_long(tmp_len); len_idx++; } else { l = ZSTR_LEN(orig_str); } - } else if (len) { - l = Z_LVAL_P(len); + } else if (!len_is_null) { + l = len_long; } else { l = ZSTR_LEN(orig_str); } |