From 8107a1da5af480839b226882e5c27fd76b191ee1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Fri, 4 Sep 2020 14:23:43 +0200 Subject: [PATCH] Use ZPP instead of custom type checks We can add these types as a native type declaration to stubs as a side-effect. Closes GH-6068 --- ext/intl/formatter/formatter.stub.php | 3 +- ext/intl/formatter/formatter_arginfo.h | 4 +- ext/intl/formatter/formatter_attr.c | 2 +- ext/intl/php_intl.stub.php | 3 +- ext/intl/php_intl_arginfo.h | 4 +- ext/ldap/ldap.c | 66 +++++++------- ext/ldap/ldap.stub.php | 12 +-- ext/ldap/ldap_arginfo.h | 6 +- ext/reflection/php_reflection.c | 23 +++-- ext/reflection/php_reflection.stub.php | 3 +- ext/reflection/php_reflection_arginfo.h | 4 +- .../ReflectionClass_constructor_002.phpt | 8 +- .../tests/ReflectionClass_toString_001.phpt | 2 +- ext/snmp/snmp.c | 60 ++++++------- ext/snmp/snmp.stub.php | 30 ++----- ext/snmp/snmp_arginfo.h | 18 ++-- ext/snmp/tests/reflection.phpt | 89 ------------------- ext/spl/spl_observer.c | 35 +++++--- ext/spl/spl_observer.stub.php | 7 +- ext/spl/spl_observer_arginfo.h | 4 +- ext/spl/tests/multiple_iterator_001.phpt | 6 +- ext/standard/basic_functions.stub.php | 54 ++++------- ext/standard/basic_functions_arginfo.h | 18 ++-- ext/standard/password.c | 78 ++++++++-------- ext/standard/streamsfuncs.c | 84 +++++++++-------- ext/standard/string.c | 71 ++++++++------- .../tests/password/password_hash_error.phpt | 8 +- .../password/password_needs_rehash_error.phpt | 9 +- .../tests/strings/str_replace_basic.phpt | 2 +- .../tests/strings/str_replace_variation3.phpt | 19 ++-- 30 files changed, 302 insertions(+), 430 deletions(-) delete mode 100644 ext/snmp/tests/reflection.phpt diff --git a/ext/intl/formatter/formatter.stub.php b/ext/intl/formatter/formatter.stub.php index 4608c1917d..8c4694e4ec 100644 --- a/ext/intl/formatter/formatter.stub.php +++ b/ext/intl/formatter/formatter.stub.php @@ -40,11 +40,10 @@ class NumberFormatter public function parseCurrency(string $value, &$currency, &$position = null) {} /** - * @param int|float $value * @return bool * @alias numfmt_set_attribute */ - public function setAttribute(int $attr, $value) {} + public function setAttribute(int $attr, int|float $value) {} /** * @return int|float|false diff --git a/ext/intl/formatter/formatter_arginfo.h b/ext/intl/formatter/formatter_arginfo.h index ffc4eb5018..e0531bcc20 100644 --- a/ext/intl/formatter/formatter_arginfo.h +++ b/ext/intl/formatter/formatter_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 041569278b83b65f67fb4848d00d5423e6728165 */ + * Stub hash: 60a05cccb434edadeec01cb7d43f919c276ce24d */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_NumberFormatter___construct, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0) @@ -33,7 +33,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_NumberFormatter_setAttribute, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) - ZEND_ARG_INFO(0, value) + ZEND_ARG_TYPE_MASK(0, value, MAY_BE_LONG|MAY_BE_DOUBLE, NULL) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_NumberFormatter_getAttribute, 0, 0, 1) diff --git a/ext/intl/formatter/formatter_attr.c b/ext/intl/formatter/formatter_attr.c index 44a2bb15ff..a90fc4caaa 100644 --- a/ext/intl/formatter/formatter_attr.c +++ b/ext/intl/formatter/formatter_attr.c @@ -129,7 +129,7 @@ PHP_FUNCTION( numfmt_set_attribute ) FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ - if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Olz", + if( zend_parse_method_parameters( ZEND_NUM_ARGS(), getThis(), "Oln", &object, NumberFormatter_ce_ptr, &attribute, &value ) == FAILURE) { RETURN_THROWS(); diff --git a/ext/intl/php_intl.stub.php b/ext/intl/php_intl.stub.php index bf5e631ba4..7662004f30 100644 --- a/ext/intl/php_intl.stub.php +++ b/ext/intl/php_intl.stub.php @@ -223,8 +223,7 @@ function numfmt_format_currency(NumberFormatter $fmt, float $value, string $curr */ function numfmt_parse_currency(NumberFormatter $fmt, string $value, &$currency, &$position = null): float|false {} -/** @param int|float $value */ -function numfmt_set_attribute(NumberFormatter $fmt, int $attr, $value): bool {} +function numfmt_set_attribute(NumberFormatter $fmt, int $attr, int|float $value): bool {} function numfmt_get_attribute(NumberFormatter $fmt, int $attr): int|float|false {} diff --git a/ext/intl/php_intl_arginfo.h b/ext/intl/php_intl_arginfo.h index cdead23643..3917187a5c 100644 --- a/ext/intl/php_intl_arginfo.h +++ b/ext/intl/php_intl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 9284fbafde8c7430a30a8fff5537bf9e6d9c6125 */ + * Stub hash: fdc7c500ddc5bc560ec54b7ce12d5961a4697a63 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_intlcal_create_instance, 0, 0, IntlCalendar, 1) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timeZone, "null") @@ -402,7 +402,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_numfmt_set_attribute, 0, 3, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, fmt, NumberFormatter, 0) ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0) - ZEND_ARG_INFO(0, value) + ZEND_ARG_TYPE_MASK(0, value, MAY_BE_LONG|MAY_BE_DOUBLE, NULL) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_numfmt_get_attribute, 0, 2, MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_FALSE) diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index c095749b6c..977e35e4c3 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -1423,7 +1423,9 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in /* {{{ php_ldap_do_search */ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) { - zval *link, *base_dn, *filter, *attrs = NULL, *attr, *serverctrls = NULL; + zval *link, *attrs = NULL, *attr, *serverctrls = NULL; + zend_string *base_dn_str, *filter_str; + HashTable *base_dn_ht, *filter_ht; zend_long attrsonly, sizelimit, timelimit, deref; zend_string *ldap_filter = NULL, *ldap_base_dn = NULL; char **ldap_attrs = NULL; @@ -1434,10 +1436,18 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) int old_ldap_sizelimit = -1, old_ldap_timelimit = -1, old_ldap_deref = -1; int num_attribs = 0, ret = 1, i, errno, argcount = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argcount, "zzz|a/lllla/", &link, &base_dn, &filter, &attrs, &attrsonly, - &sizelimit, &timelimit, &deref, &serverctrls) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(3, 9) + Z_PARAM_ZVAL(link) + Z_PARAM_STR_OR_ARRAY_HT(base_dn_str, base_dn_ht) + Z_PARAM_STR_OR_ARRAY_HT(filter_str, filter_ht) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_EX(attrs, 0, 1) + Z_PARAM_LONG(attrsonly) + Z_PARAM_LONG(sizelimit) + Z_PARAM_LONG(timelimit) + Z_PARAM_LONG(deref) + Z_PARAM_ARRAY_EX(serverctrls, 0, 1) + ZEND_PARSE_PARAMETERS_END(); /* Reverse -> fall through */ switch (argcount) { @@ -1486,38 +1496,34 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) goto cleanup; } - if (Z_TYPE_P(base_dn) == IS_ARRAY) { - nbases = zend_hash_num_elements(Z_ARRVAL_P(base_dn)); + if (base_dn_ht) { + nbases = zend_hash_num_elements(base_dn_ht); if (nbases != nlinks) { php_error_docref(NULL, E_WARNING, "Base must either be a string, or an array with the same number of elements as the links array"); ret = 0; goto cleanup; } - zend_hash_internal_pointer_reset(Z_ARRVAL_P(base_dn)); + zend_hash_internal_pointer_reset(base_dn_ht); } else { nbases = 0; /* this means string, not array */ - ldap_base_dn = zval_get_string(base_dn); + ldap_base_dn = zend_string_copy(base_dn_str); if (EG(exception)) { ret = 0; goto cleanup; } } - if (Z_TYPE_P(filter) == IS_ARRAY) { - nfilters = zend_hash_num_elements(Z_ARRVAL_P(filter)); + if (filter_ht) { + nfilters = zend_hash_num_elements(filter_ht); if (nfilters != nlinks) { php_error_docref(NULL, E_WARNING, "Filter must either be a string, or an array with the same number of elements as the links array"); ret = 0; goto cleanup; } - zend_hash_internal_pointer_reset(Z_ARRVAL_P(filter)); + zend_hash_internal_pointer_reset(filter_ht); } else { nfilters = 0; /* this means string, not array */ - ldap_filter = zval_get_string(filter); - if (EG(exception)) { - ret = 0; - goto cleanup; - } + ldap_filter = zend_string_copy(filter_str); } lds = safe_emalloc(nlinks, sizeof(ldap_linkdata), 0); @@ -1533,8 +1539,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) goto cleanup_parallel; } if (nbases != 0) { /* base_dn an array? */ - entry = zend_hash_get_current_data(Z_ARRVAL_P(base_dn)); - zend_hash_move_forward(Z_ARRVAL_P(base_dn)); + entry = zend_hash_get_current_data(base_dn_ht); + zend_hash_move_forward(base_dn_ht); ldap_base_dn = zval_get_string(entry); if (EG(exception)) { ret = 0; @@ -1542,8 +1548,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) } } if (nfilters != 0) { /* filter an array? */ - entry = zend_hash_get_current_data(Z_ARRVAL_P(filter)); - zend_hash_move_forward(Z_ARRVAL_P(filter)); + entry = zend_hash_get_current_data(filter_ht); + zend_hash_move_forward(filter_ht); ldap_filter = zval_get_string(entry); if (EG(exception)) { ret = 0; @@ -1588,23 +1594,21 @@ cleanup_parallel: efree(lds); efree(rcs); } else { - ldap_filter = zval_get_string(filter); - if (EG(exception)) { + ld = (ldap_linkdata *) zend_fetch_resource_ex(link, "ldap link", le_link); + if (ld == NULL) { ret = 0; goto cleanup; } - ldap_base_dn = zval_get_string(base_dn); - if (EG(exception)) { - ret = 0; - goto cleanup; + if (!base_dn_str) { + zend_argument_type_error(2, "must be of type string when argument #1 ($link_identifier) is a resource"); } + ldap_base_dn = zend_string_copy(base_dn_str); - ld = (ldap_linkdata *) zend_fetch_resource_ex(link, "ldap link", le_link); - if (ld == NULL) { - ret = 0; - goto cleanup; + if (!filter_str) { + zend_argument_type_error(3, "must be of type string when argument #1 ($link_identifier) is a resource"); } + ldap_filter = zend_string_copy(filter_str); if (argcount > 8) { lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls); diff --git a/ext/ldap/ldap.stub.php b/ext/ldap/ldap.stub.php index d8851b3314..e46d140545 100644 --- a/ext/ldap/ldap.stub.php +++ b/ext/ldap/ldap.stub.php @@ -35,27 +35,21 @@ function ldap_sasl_bind($link, string $binddn = UNKNOWN, string $password = UNKN /** * @param resource|array $link_identifier - * @param string|array $base_dn - * @param string|array $filter * @return resource|false */ -function ldap_read($link_identifier, $base_dn, $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {} +function ldap_read($link_identifier, array|string $base_dn, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {} /** * @param resource|array $link_identifier - * @param string|array $base_dn - * @param string|array $filter * @return resource|false */ -function ldap_list($link_identifier, $base_dn, $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {} +function ldap_list($link_identifier, array|string $base_dn, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {} /** * @param resource|array $link_identifier - * @param string|array $base_dn - * @param string|array $filter * @return resource|false */ -function ldap_search($link_identifier, $base_dn, $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {} +function ldap_search($link_identifier, array|string $base_dn, array|string $filter, array $attributes = [], int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $servercontrols = []) {} /** @param resource $link_identifier */ function ldap_free_result($link_identifier): bool {} diff --git a/ext/ldap/ldap_arginfo.h b/ext/ldap/ldap_arginfo.h index 078fe220cd..5e4cd4281c 100644 --- a/ext/ldap/ldap_arginfo.h +++ b/ext/ldap/ldap_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 6b5e8ddfbdc436fab3a263d6922146ca7c2f3845 */ + * Stub hash: c247d438a69d40353a629b09c5200d33ed8218ee */ #if defined(HAVE_ORALDAP) ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0) @@ -52,8 +52,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_read, 0, 0, 3) ZEND_ARG_INFO(0, link_identifier) - ZEND_ARG_INFO(0, base_dn) - ZEND_ARG_INFO(0, filter) + ZEND_ARG_TYPE_MASK(0, base_dn, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_MASK(0, filter, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, attributes, IS_ARRAY, 0, "[]") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, attrsonly, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sizelimit, IS_LONG, 0, "-1") diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 11b834503b..3b7c29b087 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3684,38 +3684,35 @@ ZEND_METHOD(ReflectionClassConstant, getAttributes) /* {{{ reflection_class_object_ctor */ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_object) { - zval *argument; zval *object; + zend_string *arg_class = NULL; + zend_object *arg_obj; reflection_object *intern; zend_class_entry *ce; if (is_object) { ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT(argument) + Z_PARAM_OBJ(arg_obj) ZEND_PARSE_PARAMETERS_END(); } else { ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(argument) + Z_PARAM_STR_OR_OBJ(arg_class, arg_obj) ZEND_PARSE_PARAMETERS_END(); } object = ZEND_THIS; intern = Z_REFLECTION_P(object); - if (Z_TYPE_P(argument) == IS_OBJECT) { - ZVAL_STR_COPY(reflection_prop_name(object), Z_OBJCE_P(argument)->name); - intern->ptr = Z_OBJCE_P(argument); + if (arg_obj) { + ZVAL_STR_COPY(reflection_prop_name(object), arg_obj->ce->name); + intern->ptr = arg_obj->ce; if (is_object) { - ZVAL_COPY(&intern->obj, argument); + ZVAL_OBJ_COPY(&intern->obj, arg_obj); } } else { - if (!try_convert_to_string(argument)) { - RETURN_THROWS(); - } - - if ((ce = zend_lookup_class(Z_STR_P(argument))) == NULL) { + if ((ce = zend_lookup_class(arg_class)) == NULL) { if (!EG(exception)) { - zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", Z_STRVAL_P(argument)); + zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", ZSTR_VAL(arg_class)); } RETURN_THROWS(); } diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index 539520597f..311e748e9b 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -202,8 +202,7 @@ class ReflectionClass implements Reflector { final private function __clone() {} - /** @param object|string $objectOrClass */ - public function __construct($objectOrClass) {} + public function __construct(object|string $objectOrClass) {} public function __toString(): string {} diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index 00013c7a50..c0ff2d75e2 100644 --- a/ext/reflection/php_reflection_arginfo.h +++ b/ext/reflection/php_reflection_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: beaf79270ab56d2e87a301a4a5d4444b2cc520d8 */ + * Stub hash: 1311fc5c498d6f16afb5a18aee2d60e72048174f */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0) @@ -150,7 +150,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass___clone arginfo_class_ReflectionFunctionAbstract___clone ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionClass___construct, 0, 0, 1) - ZEND_ARG_INFO(0, objectOrClass) + ZEND_ARG_TYPE_MASK(0, objectOrClass, MAY_BE_OBJECT|MAY_BE_STRING, NULL) ZEND_END_ARG_INFO() #define arginfo_class_ReflectionClass___toString arginfo_class_ReflectionFunction___toString diff --git a/ext/reflection/tests/ReflectionClass_constructor_002.phpt b/ext/reflection/tests/ReflectionClass_constructor_002.phpt index 54f4b8eda2..44ff37a962 100644 --- a/ext/reflection/tests/ReflectionClass_constructor_002.phpt +++ b/ext/reflection/tests/ReflectionClass_constructor_002.phpt @@ -28,7 +28,7 @@ try { try { var_dump(new ReflectionClass(array(1,2,3))); -} catch (Exception $e) { +} catch (TypeError $e) { echo $e->getMessage() . "\n"; } @@ -45,13 +45,11 @@ try { } ?> ---EXPECTF-- +--EXPECT-- ReflectionClass::__construct() expects exactly 1 parameter, 0 given Class "" does not exist Class "1" does not exist Class "1" does not exist - -Warning: Array to string conversion in %s on line %d -Class "Array" does not exist +ReflectionClass::__construct(): Argument #1 ($objectOrClass) must be of type object|string, array given ReflectionClass::__construct() expects exactly 1 parameter, 2 given Class "X" does not exist diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index bb9ead8ce3..00e41bfcc9 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -37,7 +37,7 @@ Class [ class ReflectionClass implements Reflector, String Method [ public method __construct ] { - Parameters [1] { - Parameter #0 [ $objectOrClass ] + Parameter #0 [ object|string $objectOrClass ] } } diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index ab512c68d0..e7f3076c12 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -659,8 +659,10 @@ retry: * OID parser (and type, value for SNMP_SET command) */ -static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_query, zend_string *oid_str, HashTable *oid_ht, zval *type, zval *value) -{ +static int php_snmp_parse_oid( + zval *object, int st, struct objid_query *objid_query, zend_string *oid_str, HashTable *oid_ht, + zend_string *type_str, HashTable *type_ht, zend_string *value_str, HashTable *value_ht +) { char *pptr; uint32_t idx_type = 0, idx_value = 0; zval *tmp_oid, *tmp_type, *tmp_value; @@ -671,15 +673,15 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg)); objid_query->vars[objid_query->count].oid = ZSTR_VAL(oid_str); if (st & SNMP_CMD_SET) { - if (Z_TYPE_P(type) == IS_STRING && Z_TYPE_P(value) == IS_STRING) { - if (Z_STRLEN_P(type) != 1) { - php_error_docref(NULL, E_WARNING, "Bogus type '%s', should be single char, got %zu", Z_STRVAL_P(type), Z_STRLEN_P(type)); + if (type_str && value_str) { + if (ZSTR_LEN(type_str) != 1) { + php_error_docref(NULL, E_WARNING, "Bogus type '%s', should be single char, got %zu", ZSTR_VAL(type_str), ZSTR_LEN(type_str)); efree(objid_query->vars); return FALSE; } - pptr = Z_STRVAL_P(type); + pptr = ZSTR_VAL(type_str); objid_query->vars[objid_query->count].type = *pptr; - objid_query->vars[objid_query->count].value = Z_STRVAL_P(value); + objid_query->vars[objid_query->count].value = ZSTR_VAL(value_str); } else { php_error_docref(NULL, E_WARNING, "Single objid and multiple type or values are not supported"); efree(objid_query->vars); @@ -698,18 +700,18 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu convert_to_string_ex(tmp_oid); objid_query->vars[objid_query->count].oid = Z_STRVAL_P(tmp_oid); if (st & SNMP_CMD_SET) { - if (Z_TYPE_P(type) == IS_STRING) { - pptr = Z_STRVAL_P(type); + if (type_str) { + pptr = ZSTR_VAL(type_str); objid_query->vars[objid_query->count].type = *pptr; - } else if (Z_TYPE_P(type) == IS_ARRAY) { - while (idx_type < Z_ARRVAL_P(type)->nNumUsed) { - tmp_type = &Z_ARRVAL_P(type)->arData[idx_type].val; + } else if (type_ht) { + while (idx_type < type_ht->nNumUsed) { + tmp_type = &type_ht->arData[idx_type].val; if (Z_TYPE_P(tmp_type) != IS_UNDEF) { break; } idx_type++; } - if (idx_type < Z_ARRVAL_P(type)->nNumUsed) { + if (idx_type < type_ht->nNumUsed) { convert_to_string_ex(tmp_type); if (Z_STRLEN_P(tmp_type) != 1) { php_error_docref(NULL, E_WARNING, "'%s': bogus type '%s', should be single char, got %zu", Z_STRVAL_P(tmp_oid), Z_STRVAL_P(tmp_type), Z_STRLEN_P(tmp_type)); @@ -726,17 +728,17 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu } } - if (Z_TYPE_P(value) == IS_STRING) { - objid_query->vars[objid_query->count].value = Z_STRVAL_P(value); - } else if (Z_TYPE_P(value) == IS_ARRAY) { - while (idx_value < Z_ARRVAL_P(value)->nNumUsed) { - tmp_value = &Z_ARRVAL_P(value)->arData[idx_value].val; + if (value_str) { + objid_query->vars[objid_query->count].value = ZSTR_VAL(value_str); + } else if (value_ht) { + while (idx_value < value_ht->nNumUsed) { + tmp_value = &value_ht->arData[idx_value].val; if (Z_TYPE_P(tmp_value) != IS_UNDEF) { break; } idx_value++; } - if (idx_value < Z_ARRVAL_P(value)->nNumUsed) { + if (idx_value < value_ht->nNumUsed) { convert_to_string_ex(tmp_value); objid_query->vars[objid_query->count].value = Z_STRVAL_P(tmp_value); idx_value++; @@ -1077,15 +1079,13 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_ */ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) { - zend_string *oid_str; - HashTable *oid_ht; - zval *value = NULL, *type = NULL; + zend_string *oid_str, *type_str = NULL, *value_str = NULL; + HashTable *oid_ht, *type_ht = NULL, *value_ht = NULL; char *a1, *a2, *a3, *a4, *a5, *a6, *a7; size_t a1_len, a2_len, a3_len, a4_len, a5_len, a6_len, a7_len; zend_bool use_orignames = 0, suffix_keys = 0; zend_long timeout = SNMP_DEFAULT_TIMEOUT; zend_long retries = SNMP_DEFAULT_RETRIES; - int argc = ZEND_NUM_ARGS(); struct objid_query objid_query; php_snmp_session *session; int session_less_mode = (getThis() == NULL); @@ -1109,8 +1109,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) Z_PARAM_STRING(a6, a6_len) Z_PARAM_STRING(a7, a7_len) Z_PARAM_STR_OR_ARRAY_HT(oid_str, oid_ht) - Z_PARAM_ZVAL(type) - Z_PARAM_ZVAL(value) + Z_PARAM_STR_OR_ARRAY_HT(type_str, type_ht) + Z_PARAM_STR_OR_ARRAY_HT(value_str, value_ht) Z_PARAM_OPTIONAL Z_PARAM_LONG(timeout) Z_PARAM_LONG(retries) @@ -1140,8 +1140,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) Z_PARAM_STRING(a1, a1_len) Z_PARAM_STRING(a2, a2_len) Z_PARAM_STR_OR_ARRAY_HT(oid_str, oid_ht) - Z_PARAM_ZVAL(type) - Z_PARAM_ZVAL(value) + Z_PARAM_STR_OR_ARRAY_HT(type_str, type_ht) + Z_PARAM_STR_OR_ARRAY_HT(value_str, value_ht) Z_PARAM_OPTIONAL Z_PARAM_LONG(timeout) Z_PARAM_LONG(retries) @@ -1165,8 +1165,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) if (st & SNMP_CMD_SET) { ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_STR_OR_ARRAY_HT(oid_str, oid_ht) - Z_PARAM_ZVAL(type) - Z_PARAM_ZVAL(value) + Z_PARAM_STR_OR_ARRAY_HT(type_str, type_ht) + Z_PARAM_STR_OR_ARRAY_HT(value_str, value_ht) ZEND_PARSE_PARAMETERS_END(); } else if (st & SNMP_CMD_WALK) { ZEND_PARSE_PARAMETERS_START(1, 4) @@ -1197,7 +1197,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) } } - if (!php_snmp_parse_oid(getThis(), st, &objid_query, oid_str, oid_ht, type, value)) { + if (!php_snmp_parse_oid(getThis(), st, &objid_query, oid_str, oid_ht, type_str, type_ht, value_str, value_ht)) { RETURN_FALSE; } diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 72d42e3461..1b7c1ac20e 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -13,11 +13,7 @@ function snmprealwalk(string $host, string $community, array|string $object_id, /** @alias snmprealwalk */ function snmpwalkoid(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} -/** - * @param array|string $type - * @param array|string $value - */ -function snmpset(string $host, string $community, array|string $object_id, $type, $value, int $timeout = -1, int $retries = -1): array|bool {} +function snmpset(string $host, string $community, array|string $object_id, array|string $type, array|string $value, int $timeout = -1, int $retries = -1): array|bool {} function snmp_get_quick_print(): bool {} @@ -38,11 +34,7 @@ function snmp2_walk(string $host, string $community, array|string $object_id, in function snmp2_real_walk(string $host, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} -/** - * @param array|string $type - * @param array|string $value - */ -function snmp2_set(string $host, string $community, array|string $object_id, $type, $value, int $timeout = -1, int $retries = -1): array|bool {} +function snmp2_set(string $host, string $community, array|string $object_id, array|string $type, array|string $value, int $timeout = -1, int $retries = -1): array|bool {} function snmp3_get(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} @@ -52,11 +44,7 @@ function snmp3_walk(string $host, string $sec_name, string $sec_level, string $a function snmp3_real_walk(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, int $timeout = -1, int $retries = -1): array|bool {} -/** - * @param array|string $type - * @param array|string $value - */ -function snmp3_set(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, $type, $value, int $timeout = -1, int $retries = -1): array|bool {} +function snmp3_set(string $host, string $sec_name, string $sec_level, string $auth_protocol, string $auth_passphrase, string $priv_protocol, string $priv_passphrase, array|string $object_id, array|string $type, array|string $value, int $timeout = -1, int $retries = -1): array|bool {} function snmp_set_valueretrieval(int $method): bool {} @@ -81,14 +69,10 @@ class SNMP public function getnext(array|string $object_id) {} /** @return array|bool */ - public function walk(array|string $object_id, bool $suffix_keys = false, int $max_repetitions = UNKNOWN, int $non_repeaters = UNKNOWN) {} - - /** - * @param array|string $type - * @param array|string $value - * @return array|bool - */ - public function set(array|string $object_id, $type, $value) {} + public function walk(array|string $object_id, bool $suffix_keys = false, int $max_repetitions = -1, int $non_repeaters = -1) {} + + /** @return array|bool */ + public function set(array|string $object_id, array|string $type, array|string $value) {} /** @return int */ public function getErrno() {} diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index 8a734fd573..5c4a0c35a8 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 02b1dd87856dfdb43039f4544f3e5225a1fb1a6e */ + * Stub hash: c9906ff8ef879e567cf8aed9a34dcff850f3e949 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmpget, 0, 3, MAY_BE_ARRAY|MAY_BE_BOOL) ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) @@ -21,8 +21,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmpset, 0, 5, MAY_BE_ARRAY|MAY_ ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, community, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, object_id, MAY_BE_ARRAY|MAY_BE_STRING, NULL) - ZEND_ARG_INFO(0, type) - ZEND_ARG_INFO(0, value) + ZEND_ARG_TYPE_MASK(0, type, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_MASK(0, value, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_LONG, 0, "-1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retries, IS_LONG, 0, "-1") ZEND_END_ARG_INFO() @@ -82,8 +82,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_snmp3_set, 0, 10, MAY_BE_ARRAY|M ZEND_ARG_TYPE_INFO(0, priv_protocol, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, priv_passphrase, IS_STRING, 0) ZEND_ARG_TYPE_MASK(0, object_id, MAY_BE_ARRAY|MAY_BE_STRING, NULL) - ZEND_ARG_INFO(0, type) - ZEND_ARG_INFO(0, value) + ZEND_ARG_TYPE_MASK(0, type, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_MASK(0, value, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_LONG, 0, "-1") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retries, IS_LONG, 0, "-1") ZEND_END_ARG_INFO() @@ -132,14 +132,14 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SNMP_walk, 0, 0, 1) ZEND_ARG_TYPE_MASK(0, object_id, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, suffix_keys, _IS_BOOL, 0, "false") - ZEND_ARG_TYPE_INFO(0, max_repetitions, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, non_repeaters, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, max_repetitions, IS_LONG, 0, "-1") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, non_repeaters, IS_LONG, 0, "-1") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SNMP_set, 0, 0, 3) ZEND_ARG_TYPE_MASK(0, object_id, MAY_BE_ARRAY|MAY_BE_STRING, NULL) - ZEND_ARG_INFO(0, type) - ZEND_ARG_INFO(0, value) + ZEND_ARG_TYPE_MASK(0, type, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_MASK(0, value, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_END_ARG_INFO() #define arginfo_class_SNMP_getErrno arginfo_class_SNMP_close diff --git a/ext/snmp/tests/reflection.phpt b/ext/snmp/tests/reflection.phpt deleted file mode 100644 index 53fc063be6..0000000000 --- a/ext/snmp/tests/reflection.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -Test SNMP Reflection ---SKIPIF-- - ---FILE-- - ---EXPECT-- -Method [ public method __construct ] { - - - Parameters [5] { - Parameter #0 [ int $version ] - Parameter #1 [ string $host ] - Parameter #2 [ string $community ] - Parameter #3 [ int $timeout ] - Parameter #4 [ int $retries ] - } -} -Method [ public method close ] { - - - Parameters [0] { - } -} -Method [ public method setSecurity ] { - - - Parameters [7] { - Parameter #0 [ string $sec_level ] - Parameter #1 [ string $auth_protocol ] - Parameter #2 [ string $auth_passphrase ] - Parameter #3 [ string $priv_protocol ] - Parameter #4 [ string $priv_passphrase ] - Parameter #5 [ string $contextName ] - Parameter #6 [ string $contextEngineID ] - } -} -Method [ public method get ] { - - - Parameters [2] { - Parameter #0 [ $object_id ] - Parameter #1 [ bool $use_orignames ] - } -} -Method [ public method getnext ] { - - - Parameters [1] { - Parameter #0 [ $object_id ] - } -} -Method [ public method walk ] { - - - Parameters [4] { - Parameter #0 [ $object_id ] - Parameter #1 [ bool $suffix_keys ] - Parameter #2 [ int $max_repetitions ] - Parameter #3 [ int $non_repeaters ] - } -} -Method [ public method set ] { - - - Parameters [3] { - Parameter #0 [ $object_id ] - Parameter #1 [ $type ] - Parameter #2 [ $value ] - } -} -Method [ public method getErrno ] { - - - Parameters [0] { - } -} -Method [ public method getError ] { - - - Parameters [0] { - } -} diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index eaad4db815..3f134b77db 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -935,34 +935,43 @@ PHP_METHOD(MultipleIterator, setFlags) /* {{{ Attach a new iterator */ PHP_METHOD(MultipleIterator, attachIterator) { - spl_SplObjectStorage *intern; - zval *iterator = NULL, *info = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|z!", &iterator, zend_ce_iterator, &info) == FAILURE) { - RETURN_THROWS(); - } + spl_SplObjectStorage *intern; + zval *iterator = NULL; + zval zinfo; + zend_string *info_str; + zend_long info_long; + zend_bool info_is_null = 1; + + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_OBJECT_OF_CLASS(iterator, zend_ce_iterator) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_LONG_OR_NULL(info_str, info_long, info_is_null) + ZEND_PARSE_PARAMETERS_END(); intern = Z_SPLOBJSTORAGE_P(ZEND_THIS); - if (info != NULL) { + if (!info_is_null) { spl_SplObjectStorageElement *element; - if (Z_TYPE_P(info) != IS_LONG && Z_TYPE_P(info) != IS_STRING) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Info must be NULL, integer or string", 0); - RETURN_THROWS(); + if (info_str) { + ZVAL_STR(&zinfo, info_str); + } else { + ZVAL_LONG(&zinfo, info_long); } zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos); while ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) != NULL) { - if (fast_is_identical_function(info, &element->inf)) { + if (fast_is_identical_function(&zinfo, &element->inf)) { zend_throw_exception(spl_ce_InvalidArgumentException, "Key duplication error", 0); RETURN_THROWS(); } zend_hash_move_forward_ex(&intern->storage, &intern->pos); } - } - spl_object_storage_attach(intern, iterator, info); + spl_object_storage_attach(intern, iterator, &zinfo); + } else { + spl_object_storage_attach(intern, iterator, NULL); + } } /* }}} */ diff --git a/ext/spl/spl_observer.stub.php b/ext/spl/spl_observer.stub.php index e399b13c98..475f3b8dc7 100644 --- a/ext/spl/spl_observer.stub.php +++ b/ext/spl/spl_observer.stub.php @@ -120,11 +120,8 @@ class MultipleIterator implements Iterator /** @return void */ public function setFlags(int $flags) {} - /** - * @param int|string|null $info - * @return void - */ - public function attachIterator(Iterator $iterator, $info = null) {} + /** @return void */ + public function attachIterator(Iterator $iterator, string|int|null $info = null) {} /** @return void */ public function detachIterator(Iterator $iterator) {} diff --git a/ext/spl/spl_observer_arginfo.h b/ext/spl/spl_observer_arginfo.h index 3c08a44268..eed972b283 100644 --- a/ext/spl/spl_observer_arginfo.h +++ b/ext/spl/spl_observer_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: f795244462fc7b6aed3f38f6b2e1985b3a2ab7c1 */ + * Stub hash: aab6134fb2223ffe4d686f3a601e66da17c99511 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplObserver_update, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, subject, SplSubject, 0) @@ -94,7 +94,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MultipleIterator_attachIterator, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, info, "null") + ZEND_ARG_TYPE_MASK(0, info, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MultipleIterator_detachIterator, 0, 0, 1) diff --git a/ext/spl/tests/multiple_iterator_001.phpt b/ext/spl/tests/multiple_iterator_001.phpt index 56a08da272..7f2b971b55 100644 --- a/ext/spl/tests/multiple_iterator_001.phpt +++ b/ext/spl/tests/multiple_iterator_001.phpt @@ -79,8 +79,8 @@ echo "-- Associate with invalid value --\n"; try { $m->attachIterator($iter3, new stdClass()); -} catch(InvalidArgumentException $e) { - echo "InvalidArgumentException thrown: " . $e->getMessage() . "\n"; +} catch(TypeError $e) { + echo "TypeError thrown: " . $e->getMessage() . "\n"; } echo "-- Associate with duplicate value --\n"; @@ -297,7 +297,7 @@ array(3) { int(3) } -- Associate with invalid value -- -InvalidArgumentException thrown: Info must be NULL, integer or string +TypeError thrown: MultipleIterator::attachIterator(): Argument #2 ($info) must be of type string|int|null, stdClass given -- Associate with duplicate value -- InvalidArgumentException thrown: Key duplication error -- Count, contains, detach, count, contains, iterate -- diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index 73a82b627d..75819c7fb5 100755 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -121,8 +121,8 @@ function array_search(mixed $needle, array $haystack, bool $strict = false): int function extract(array &$array, int $extract_type = EXTR_OVERWRITE, string $prefix = ""): int {} /** - * @param string|array $var_name - * @param string|array $var_names + * @param array|string $var_name + * @param array|string $var_names */ function compact($var_name, ...$var_names): array {} @@ -131,11 +131,10 @@ function array_fill(int $start_key, int $num, mixed $val): array {} function array_fill_keys(array $keys, mixed $val): array {} /** - * @param int|float|string $low - * @param int|float|string $high - * @param int|float $step + * @param string|int|float $low + * @param string|int|float $high */ -function range($low, $high, $step = 1): array {} +function range($low, $high, int|float $step = 1): array {} function shuffle(array &$array): bool {} @@ -245,11 +244,11 @@ function array_filter(array $array, ?callable $callback = null, int $use_keys = function array_map(?callable $callback, array $array1, array ...$arrays): array {} -/** @param int|string $key */ +/** @param string|int $key */ function array_key_exists($key, array $search): bool {} /** - * @param int|string $key + * @param string|int $key * @alias array_key_exists */ function key_exists($key, array $search): bool {} @@ -507,10 +506,10 @@ function header(string $string, bool $replace = true, int $http_response_code = function header_remove(string $name = UNKNOWN): void {} -/** @param int|array $expires_or_options */ +/** @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 {} -/** @param int|array $expires_or_options */ +/** @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 http_response_code(int $response_code = 0): int|bool {} @@ -621,8 +620,7 @@ function substr(string $str, int $start, ?int $length = null): string|false {} * @param mixed $start * @param mixed $length */ -function substr_replace( - string|array $str, string|array $replace, $start, $length = UNKNOWN): string|array|false {} +function substr_replace(array|string $str, string|array $replace, $start, $length = UNKNOWN): string|array|false {} function quotemeta(string $str): string {} @@ -651,21 +649,11 @@ function stripcslashes(string $str): string {} function stripslashes(string $str): string {} -/** - * @param string|array $search - * @param string|array $replace - * @param int $replace_count - */ -function str_replace( - $search, $replace, string|array $subject, &$replace_count = UNKNOWN): string|array {} +/** @param int $replace_count */ +function str_replace(array|string $search, array|string $replace, string|array $subject, &$replace_count = UNKNOWN): string|array {} -/** - * @param string|array $search - * @param string|array $replace - * @param int $replace_count - */ -function str_ireplace( - $search, $replace, string|array $subject, &$replace_count = UNKNOWN): string|array {} +/** @param int $replace_count */ +function str_ireplace(array|string $search, array|string $replace, string|array $subject, &$replace_count = UNKNOWN): string|array {} function hebrev(string $str, int $max_chars_per_line = 0): string {} @@ -1166,11 +1154,9 @@ function unpack(string $format, string $data, int $offset = 0): array|false {} function password_get_info(string $hash): ?array {} -/** @param string|int $algo */ -function password_hash(string $password, $algo, array $options = []): string {} +function password_hash(string $password, string|int|null $algo, array $options = []): string {} -/** @param string|int $algo */ -function password_needs_rehash(string $hash, $algo, array $options = []): bool {} +function password_needs_rehash(string $hash, string|int $algo, array $options = []): bool {} function password_verify(string $password, string $hash): bool {} @@ -1240,12 +1226,8 @@ function stream_context_set_params($context, array $params): bool {} /** @param resource $context */ function stream_context_get_params($context): array {} -/** - * @param resource $context - * @param array|string $param2 - * @param mixed $value - */ -function stream_context_set_option($context, $param2, string $option_name = UNKNOWN, mixed $value = UNKNOWN): bool {} +/** @param resource $context */ +function stream_context_set_option($context, array|string $wrapper_or_options, ?string $option_name = null, mixed $value = UNKNOWN): bool {} /** @param resource $stream_or_context */ function stream_context_get_options($stream_or_context): array {} diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index 31200dbb92..9d13b25b85 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: 8b6ef365e9635c92ef86adb40b2aba077867f3b2 */ + * Stub hash: 010a6e0dee6d5e419e66eeefadd4dfabbbddfaca */ 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) @@ -183,7 +183,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_range, 0, 2, IS_ARRAY, 0) ZEND_ARG_INFO(0, low) ZEND_ARG_INFO(0, high) - ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, step, "1") + ZEND_ARG_TYPE_MASK(0, step, MAY_BE_LONG|MAY_BE_DOUBLE, "1") ZEND_END_ARG_INFO() #define arginfo_shuffle arginfo_natsort @@ -938,7 +938,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr, 0, 2, MAY_BE_STRING|MAY_ 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_STRING|MAY_BE_ARRAY, NULL) + 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(0, length) @@ -989,8 +989,8 @@ ZEND_END_ARG_INFO() #define arginfo_stripslashes arginfo_base64_encode ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_str_replace, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY) - ZEND_ARG_INFO(0, search) - ZEND_ARG_INFO(0, replace) + ZEND_ARG_TYPE_MASK(0, search, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_MASK(0, replace, MAY_BE_ARRAY|MAY_BE_STRING, NULL) ZEND_ARG_TYPE_MASK(0, subject, MAY_BE_STRING|MAY_BE_ARRAY, NULL) ZEND_ARG_INFO(1, replace_count) ZEND_END_ARG_INFO() @@ -1771,13 +1771,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_password_hash, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) - ZEND_ARG_INFO(0, algo) + ZEND_ARG_TYPE_MASK(0, algo, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_NULL, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_password_needs_rehash, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, hash, IS_STRING, 0) - ZEND_ARG_INFO(0, algo) + ZEND_ARG_TYPE_MASK(0, algo, MAY_BE_STRING|MAY_BE_LONG, NULL) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() @@ -1877,8 +1877,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_option, 0, 2, _IS_BOOL, 0) ZEND_ARG_INFO(0, context) - ZEND_ARG_INFO(0, param2) - ZEND_ARG_TYPE_INFO(0, option_name, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, wrapper_or_options, MAY_BE_ARRAY|MAY_BE_STRING, NULL) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, option_name, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) ZEND_END_ARG_INFO() diff --git a/ext/standard/password.c b/ext/standard/password.c index de21569a44..687a780d1d 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -487,46 +487,40 @@ const php_password_algo* php_password_algo_find(const zend_string *ident) { return Z_PTR_P(tmp); } -static const php_password_algo* php_password_algo_find_zval_ex(zval *arg, const php_password_algo* default_algo) { - if (!arg || (Z_TYPE_P(arg) == IS_NULL)) { - return default_algo; +static const php_password_algo* php_password_algo_find_zval(zend_string *arg_str, zend_long arg_long, zend_bool arg_is_null) { + if (arg_is_null) { + return php_password_algo_default(); + } + + if (arg_str) { + return php_password_algo_find(arg_str); } - if (Z_TYPE_P(arg) == IS_LONG) { - switch (Z_LVAL_P(arg)) { - case 0: return default_algo; - case 1: return &php_password_algo_bcrypt; + switch (arg_long) { + case 0: return php_password_algo_default(); + case 1: return &php_password_algo_bcrypt; #if HAVE_ARGON2LIB - case 2: return &php_password_algo_argon2i; - case 3: return &php_password_algo_argon2id; + case 2: return &php_password_algo_argon2i; + case 3: return &php_password_algo_argon2id; #else - case 2: - { - zend_string *n = zend_string_init("argon2i", sizeof("argon2i")-1, 0); - const php_password_algo* ret = php_password_algo_find(n); - zend_string_release(n); - return ret; - } - case 3: - { - zend_string *n = zend_string_init("argon2id", sizeof("argon2id")-1, 0); - const php_password_algo* ret = php_password_algo_find(n); - zend_string_release(n); - return ret; - } + case 2: + { + zend_string *n = zend_string_init("argon2i", sizeof("argon2i")-1, 0); + const php_password_algo* ret = php_password_algo_find(n); + zend_string_release(n); + return ret; + } + case 3: + { + zend_string *n = zend_string_init("argon2id", sizeof("argon2id")-1, 0); + const php_password_algo* ret = php_password_algo_find(n); + zend_string_release(n); + return ret; + } #endif - } - return NULL; } - if (Z_TYPE_P(arg) != IS_STRING) { - return NULL; - } - - return php_password_algo_find(Z_STR_P(arg)); -} -static const php_password_algo* php_password_algo_find_zval(zval *arg) { - return php_password_algo_find_zval_ex(arg, php_password_algo_default()); + return NULL; } zend_string *php_password_algo_extract_ident(const zend_string* hash) { @@ -605,17 +599,19 @@ PHP_FUNCTION(password_needs_rehash) { const php_password_algo *old_algo, *new_algo; zend_string *hash; - zval *znew_algo; + zend_string *new_algo_str; + zend_long new_algo_long; + zend_bool new_algo_is_null; zend_array *options = 0; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(hash) - Z_PARAM_ZVAL(znew_algo) + Z_PARAM_STR_OR_LONG_OR_NULL(new_algo_str, new_algo_long, new_algo_is_null) Z_PARAM_OPTIONAL Z_PARAM_ARRAY_HT(options) ZEND_PARSE_PARAMETERS_END(); - new_algo = php_password_algo_find_zval(znew_algo); + new_algo = php_password_algo_find_zval(new_algo_str, new_algo_long, new_algo_is_null); if (!new_algo) { /* Unknown new algorithm, never prompt to rehash. */ RETURN_FALSE; @@ -651,22 +647,22 @@ PHP_FUNCTION(password_verify) PHP_FUNCTION(password_hash) { zend_string *password, *digest = NULL; - zval *zalgo; + zend_string *algo_str; + zend_long algo_long; + zend_bool algo_is_null; const php_password_algo *algo; zend_array *options = NULL; ZEND_PARSE_PARAMETERS_START(2, 3) Z_PARAM_STR(password) - Z_PARAM_ZVAL(zalgo) + Z_PARAM_STR_OR_LONG_OR_NULL(algo_str, algo_long, algo_is_null) Z_PARAM_OPTIONAL Z_PARAM_ARRAY_HT(options) ZEND_PARSE_PARAMETERS_END(); - algo = php_password_algo_find_zval(zalgo); + algo = php_password_algo_find_zval(algo_str, algo_long, algo_is_null); if (!algo) { - zend_string *algostr = zval_get_string(zalgo); zend_argument_value_error(2, "must be a valid password hashing algorithm"); - zend_string_release(algostr); RETURN_THROWS(); } diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 0bc475498f..f56f52930c 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -868,13 +868,13 @@ static void user_space_stream_notifier_dtor(php_stream_notifier *notifier) } } -static int parse_context_options(php_stream_context *context, zval *options) +static int parse_context_options(php_stream_context *context, HashTable *options) { zval *wval, *oval; zend_string *wkey, *okey; int ret = SUCCESS; - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), wkey, wval) { + ZEND_HASH_FOREACH_STR_KEY_VAL(options, wkey, wval) { ZVAL_DEREF(wval); if (wkey && Z_TYPE_P(wval) == IS_ARRAY) { ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(wval), okey, oval) { @@ -891,12 +891,12 @@ static int parse_context_options(php_stream_context *context, zval *options) return ret; } -static int parse_context_params(php_stream_context *context, zval *params) +static int parse_context_params(php_stream_context *context, HashTable *params) { int ret = SUCCESS; zval *tmp; - if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(params), "notification", sizeof("notification")-1))) { + if (NULL != (tmp = zend_hash_str_find(params, "notification", sizeof("notification")-1))) { if (context->notifier) { php_stream_notification_free(context->notifier); @@ -908,9 +908,9 @@ static int parse_context_params(php_stream_context *context, zval *params) ZVAL_COPY(&context->notifier->ptr, tmp); context->notifier->dtor = user_space_stream_notifier_dtor; } - if (NULL != (tmp = zend_hash_str_find(Z_ARRVAL_P(params), "options", sizeof("options")-1))) { + if (NULL != (tmp = zend_hash_str_find(params, "options", sizeof("options")-1))) { if (Z_TYPE_P(tmp) == IS_ARRAY) { - return parse_context_options(context, tmp); + return parse_context_options(context, Z_ARRVAL_P(tmp)); } else { zend_type_error("Invalid stream/context parameter"); return FAILURE; @@ -975,41 +975,45 @@ PHP_FUNCTION(stream_context_set_option) { zval *zcontext = NULL; php_stream_context *context; + zend_string *wrappername; + HashTable *options; + char *optionname = NULL; + size_t optionname_len; + zval *zvalue = NULL; - if (ZEND_NUM_ARGS() == 2) { - zval *options; + ZEND_PARSE_PARAMETERS_START(2, 4) + Z_PARAM_RESOURCE(zcontext) + Z_PARAM_STR_OR_ARRAY_HT(wrappername, options) + Z_PARAM_OPTIONAL + Z_PARAM_STRING_OR_NULL(optionname, optionname_len) + Z_PARAM_ZVAL(zvalue) + ZEND_PARSE_PARAMETERS_END(); + + /* figure out where the context is coming from exactly */ + if (!(context = decode_context_param(zcontext))) { + zend_argument_type_error(1, "must be a valid stream/context"); + RETURN_THROWS(); + } - ZEND_PARSE_PARAMETERS_START(2, 2) - Z_PARAM_RESOURCE(zcontext) - Z_PARAM_ARRAY(options) - ZEND_PARSE_PARAMETERS_END(); + if (options) { + if (optionname) { + zend_argument_value_error(3, "must be null when argument #2 ($wrapper_or_options) is an array"); + RETURN_THROWS(); + } - /* figure out where the context is coming from exactly */ - if (!(context = decode_context_param(zcontext))) { - zend_argument_type_error(1, "must be a valid stream/context"); + if (zvalue) { + zend_argument_value_error(4, "cannot be provided when argument #2 ($wrapper_or_options) is an array"); RETURN_THROWS(); } RETURN_BOOL(parse_context_options(context, options) == SUCCESS); } else { - zval *zvalue; - char *wrappername, *optionname; - size_t wrapperlen, optionlen; - - ZEND_PARSE_PARAMETERS_START(4, 4) - Z_PARAM_RESOURCE(zcontext) - Z_PARAM_STRING(wrappername, wrapperlen) - Z_PARAM_STRING(optionname, optionlen) - Z_PARAM_ZVAL(zvalue) - ZEND_PARSE_PARAMETERS_END(); - - /* figure out where the context is coming from exactly */ - if (!(context = decode_context_param(zcontext))) { - zend_argument_type_error(1, "must be a valid stream/context"); + if (!optionname) { + zend_argument_value_error(3, "cannot be null when argument #2 ($wrapper_or_options) is a string"); RETURN_THROWS(); } - RETURN_BOOL(php_stream_context_set_option(context, wrappername, optionname, zvalue) == SUCCESS); + RETURN_BOOL(php_stream_context_set_option(context, ZSTR_VAL(wrappername), optionname, zvalue) == SUCCESS); } } /* }}} */ @@ -1017,12 +1021,13 @@ PHP_FUNCTION(stream_context_set_option) /* {{{ Set parameters for a file context */ PHP_FUNCTION(stream_context_set_params) { - zval *params, *zcontext; + HashTable *params; + zval *zcontext; php_stream_context *context; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_RESOURCE(zcontext) - Z_PARAM_ARRAY(params) + Z_PARAM_ARRAY_HT(params) ZEND_PARSE_PARAMETERS_END(); context = decode_context_param(zcontext); @@ -1064,12 +1069,12 @@ PHP_FUNCTION(stream_context_get_params) /* {{{ Get a handle on the default file/stream context and optionally set parameters */ PHP_FUNCTION(stream_context_get_default) { - zval *params = NULL; + HashTable *params = NULL; php_stream_context *context; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_ARRAY(params) + Z_PARAM_ARRAY_HT(params) ZEND_PARSE_PARAMETERS_END(); if (FG(default_context) == NULL) { @@ -1090,11 +1095,11 @@ PHP_FUNCTION(stream_context_get_default) /* {{{ Set default file/stream context, returns the context as a resource */ PHP_FUNCTION(stream_context_set_default) { - zval *options = NULL; + HashTable *options; php_stream_context *context; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(options) + Z_PARAM_ARRAY_HT(options) ZEND_PARSE_PARAMETERS_END(); if (FG(default_context) == NULL) { @@ -1113,13 +1118,14 @@ PHP_FUNCTION(stream_context_set_default) /* {{{ Create a file context and optionally set parameters */ PHP_FUNCTION(stream_context_create) { - zval *options = NULL, *params = NULL; + HashTable *options = NULL; + HashTable *params = NULL; php_stream_context *context; ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL - Z_PARAM_ARRAY_OR_NULL(options) - Z_PARAM_ARRAY_OR_NULL(params) + Z_PARAM_ARRAY_HT_OR_NULL(options) + Z_PARAM_ARRAY_HT_OR_NULL(params) ZEND_PARSE_PARAMETERS_END(); context = php_stream_context_alloc(); diff --git a/ext/standard/string.c b/ext/standard/string.c index bdaaeea47f..5631ce4ac0 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4083,8 +4083,10 @@ PHPAPI void php_stripslashes(zend_string *str) #define _isnewline(c) (((((unsigned char) c) == '\n' || ((unsigned char) c) == '\r')) ? 1 : 0) /* {{{ php_str_replace_in_subject */ -static zend_long php_str_replace_in_subject(zval *search, zval *replace, zend_string *subject_str, zval *result, int case_sensitivity) -{ +static zend_long php_str_replace_in_subject( + zend_string *search_str, HashTable *search_ht, zend_string *replace_str, HashTable *replace_ht, + zend_string *subject_str, zval *result, int case_sensitivity +) { zval *search_entry; zend_string *tmp_result; char *replace_value = NULL; @@ -4099,37 +4101,37 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zend_st } /* If search is an array */ - if (Z_TYPE_P(search) == IS_ARRAY) { + if (search_ht) { /* Duplicate subject string for repeated replacement */ zend_string_addref(subject_str); - if (Z_TYPE_P(replace) == IS_ARRAY) { + if (replace_ht) { replace_idx = 0; } else { /* Set replacement value to the passed one */ - replace_value = Z_STRVAL_P(replace); - replace_len = Z_STRLEN_P(replace); + replace_value = ZSTR_VAL(replace_str); + replace_len = ZSTR_LEN(replace_str); } /* For each entry in the search array, get the entry */ - ZEND_HASH_FOREACH_VAL_IND(Z_ARRVAL_P(search), search_entry) { + ZEND_HASH_FOREACH_VAL_IND(search_ht, search_entry) { /* Make sure we're dealing with strings. */ zend_string *tmp_search_str; zend_string *search_str = zval_get_tmp_string(search_entry, &tmp_search_str); zend_string *replace_entry_str, *tmp_replace_entry_str = NULL; /* If replace is an array. */ - if (Z_TYPE_P(replace) == IS_ARRAY) { + if (replace_ht) { /* Get current entry */ zval *replace_entry = NULL; - while (replace_idx < Z_ARRVAL_P(replace)->nNumUsed) { - replace_entry = &Z_ARRVAL_P(replace)->arData[replace_idx].val; + while (replace_idx < replace_ht->nNumUsed) { + replace_entry = &replace_ht->arData[replace_idx].val; if (Z_TYPE_P(replace_entry) != IS_UNDEF) { break; } replace_idx++; } - if (replace_idx < Z_ARRVAL_P(replace)->nNumUsed) { + if (replace_idx < replace_ht->nNumUsed) { /* Make sure we're dealing with strings. */ replace_entry_str = zval_get_tmp_string(replace_entry, &tmp_replace_entry_str); @@ -4205,25 +4207,24 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zend_st zend_string_release_ex(lc_subject_str, 0); } } else { - ZEND_ASSERT(Z_TYPE_P(search) == IS_STRING); - if (Z_STRLEN_P(search) == 1) { + ZEND_ASSERT(search_str); + if (ZSTR_LEN(search_str) == 1) { ZVAL_STR(result, php_char_to_str_ex(subject_str, - Z_STRVAL_P(search)[0], - Z_STRVAL_P(replace), - Z_STRLEN_P(replace), + ZSTR_VAL(search_str)[0], + ZSTR_VAL(replace_str), + ZSTR_LEN(replace_str), case_sensitivity, &replace_count)); - } else if (Z_STRLEN_P(search) > 1) { + } else if (ZSTR_LEN(search_str) > 1) { if (case_sensitivity) { ZVAL_STR(result, php_str_to_str_ex(subject_str, - Z_STRVAL_P(search), Z_STRLEN_P(search), - Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); + ZSTR_VAL(search_str), ZSTR_LEN(search_str), + ZSTR_VAL(replace_str), ZSTR_LEN(replace_str), &replace_count)); } else { lc_subject_str = php_string_tolower(subject_str); ZVAL_STR(result, php_str_to_str_i_ex(subject_str, ZSTR_VAL(lc_subject_str), - Z_STR_P(search), - Z_STRVAL_P(replace), Z_STRLEN_P(replace), &replace_count)); + search_str, ZSTR_VAL(replace_str), ZSTR_LEN(replace_str), &replace_count)); zend_string_release_ex(lc_subject_str, 0); } } else { @@ -4237,9 +4238,13 @@ static zend_long php_str_replace_in_subject(zval *search, zval *replace, zend_st /* {{{ php_str_replace_common */ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensitivity) { + zend_string *search_str; + HashTable *search_ht; + zend_string *replace_str; + HashTable *replace_ht; zend_string *subject_str; HashTable *subject_ht; - zval *search, *replace, *subject_entry, *zcount = NULL; + zval *subject_entry, *zcount = NULL; zval result; zend_string *string_key; zend_ulong num_key; @@ -4247,24 +4252,18 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit int argc = ZEND_NUM_ARGS(); ZEND_PARSE_PARAMETERS_START(3, 4) - Z_PARAM_ZVAL(search) - Z_PARAM_ZVAL(replace) + Z_PARAM_STR_OR_ARRAY_HT(search_str, search_ht) + Z_PARAM_STR_OR_ARRAY_HT(replace_str, replace_ht) Z_PARAM_STR_OR_ARRAY_HT(subject_str, subject_ht) Z_PARAM_OPTIONAL Z_PARAM_ZVAL(zcount) ZEND_PARSE_PARAMETERS_END(); /* Make sure we're dealing with strings and do the replacement. */ - if (Z_TYPE_P(search) != IS_ARRAY) { - convert_to_string_ex(search); - if (Z_TYPE_P(replace) != IS_STRING) { - convert_to_string_ex(replace); - } - } else if (Z_TYPE_P(replace) != IS_ARRAY) { - convert_to_string_ex(replace); - } - - if (EG(exception)) { + if (search_str && replace_ht) { + zend_argument_type_error(2, "must be of type %s when argument #1 ($search) is %s", + search_str ? "string" : "array", search_str ? "a string" : "an array" + ); RETURN_THROWS(); } @@ -4278,7 +4277,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit zend_string *tmp_subject_str; ZVAL_DEREF(subject_entry); subject_str = zval_get_tmp_string(subject_entry, &tmp_subject_str); - count += php_str_replace_in_subject(search, replace, subject_str, &result, case_sensitivity); + count += php_str_replace_in_subject(search_str, search_ht, replace_str, replace_ht, subject_str, &result, case_sensitivity); zend_tmp_string_release(tmp_subject_str); /* Add to return array */ @@ -4289,7 +4288,7 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit } } ZEND_HASH_FOREACH_END(); } else { /* if subject is not an array */ - count = php_str_replace_in_subject(search, replace, subject_str, return_value, case_sensitivity); + count = php_str_replace_in_subject(search_str, search_ht, replace_str, replace_ht, subject_str, return_value, case_sensitivity); } if (argc > 3) { ZEND_TRY_ASSIGN_REF_LONG(zcount, count); diff --git a/ext/standard/tests/password/password_hash_error.phpt b/ext/standard/tests/password/password_hash_error.phpt index 0dc056ea34..ddb5793c81 100644 --- a/ext/standard/tests/password/password_hash_error.phpt +++ b/ext/standard/tests/password/password_hash_error.phpt @@ -12,7 +12,7 @@ try { try { password_hash("foo", array()); -} catch (ValueError $exception) { +} catch (TypeError $exception) { echo $exception->getMessage() . "\n"; } @@ -35,11 +35,9 @@ try { } ?> ---EXPECTF-- +--EXPECT-- password_hash() expects at least 2 parameters, 1 given - -Warning: Array to string conversion in %s on line %d -password_hash(): Argument #2 ($algo) must be a valid password hashing algorithm +password_hash(): Argument #2 ($algo) must be of type string|int|null, array given password_hash(): Argument #3 ($options) must be of type array, stdClass given password_hash(): Argument #3 ($options) must be of type array, string given password_hash(): Argument #1 ($password) must be of type string, array given diff --git a/ext/standard/tests/password/password_needs_rehash_error.phpt b/ext/standard/tests/password/password_needs_rehash_error.phpt index 0b64b0c82e..aef86ee124 100644 --- a/ext/standard/tests/password/password_needs_rehash_error.phpt +++ b/ext/standard/tests/password/password_needs_rehash_error.phpt @@ -2,7 +2,6 @@ Test error operation of password_needs_rehash() --FILE-- getMessage(), "\n"; } -var_dump(password_needs_rehash('', [])); +try { + var_dump(password_needs_rehash('', [])); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} try { var_dump(password_needs_rehash(array(), PASSWORD_BCRYPT)); @@ -28,7 +31,7 @@ echo "OK!"; ?> --EXPECT-- password_needs_rehash() expects at least 2 parameters, 1 given -bool(false) +password_needs_rehash(): Argument #2 ($algo) must be of type string|int|null, array given password_needs_rehash(): Argument #1 ($hash) must be of type string, array given password_needs_rehash(): Argument #3 ($options) must be of type array, string given OK! diff --git a/ext/standard/tests/strings/str_replace_basic.phpt b/ext/standard/tests/strings/str_replace_basic.phpt index bbabf198ee..4dfbd098ef 100644 --- a/ext/standard/tests/strings/str_replace_basic.phpt +++ b/ext/standard/tests/strings/str_replace_basic.phpt @@ -40,5 +40,5 @@ string(1) "q" int(1) string(0) "" int(0) -str_replace(): Argument #3 ($subject) must be of type string|array, resource given +str_replace(): Argument #1 ($search) must be of type array|string, resource given resource(%d) of type (stream) diff --git a/ext/standard/tests/strings/str_replace_variation3.phpt b/ext/standard/tests/strings/str_replace_variation3.phpt index 3c0562615a..f08d8c7dc1 100644 --- a/ext/standard/tests/strings/str_replace_variation3.phpt +++ b/ext/standard/tests/strings/str_replace_variation3.phpt @@ -80,8 +80,11 @@ var_dump(str_replace( array("a", "a", "b"), ); var_dump($count); -var_dump(str_replace("a", array("q", "q", "c"), array("aaa"), $count)); -var_dump($count); +try { + str_replace("a", array("q", "q", "c"), array("aaa"), $count); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} var_dump(str_replace("a", 1, array("aaa", "bbb"), $count)); var_dump($count); @@ -175,13 +178,7 @@ array(2) { string(3) "ccc" } int(6) - -Warning: Array to string conversion in %s on line %d -array(1) { - [0]=> - string(15) "ArrayArrayArray" -} -int(3) +str_replace(): Argument #2 ($replace) must be of type string when argument #1 ($search) is a string array(2) { [0]=> string(3) "111" @@ -198,8 +195,8 @@ array(2) { int(1) -- Testing Resources -- -str_replace(): Argument #3 ($subject) must be of type string|array, resource given -str_replace(): Argument #3 ($subject) must be of type string|array, resource given +str_replace(): Argument #3 ($subject) must be of type array|string, resource given +str_replace(): Argument #3 ($subject) must be of type array|string, resource given -- Testing a longer and heredoc string -- string(623) "FOUNDghijklmnopqrstuvwxyz0123456789FOUNDghijklmnopqrstuvwxyz0123456789 -- 2.40.0