]> granicus.if.org Git - php/commitdiff
Use ZPP instead of custom type checks
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 4 Sep 2020 12:23:43 +0000 (14:23 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 4 Sep 2020 12:32:34 +0000 (14:32 +0200)
We can add these types as a native type declaration to stubs as a side-effect. Closes GH-6068

30 files changed:
ext/intl/formatter/formatter.stub.php
ext/intl/formatter/formatter_arginfo.h
ext/intl/formatter/formatter_attr.c
ext/intl/php_intl.stub.php
ext/intl/php_intl_arginfo.h
ext/ldap/ldap.c
ext/ldap/ldap.stub.php
ext/ldap/ldap_arginfo.h
ext/reflection/php_reflection.c
ext/reflection/php_reflection.stub.php
ext/reflection/php_reflection_arginfo.h
ext/reflection/tests/ReflectionClass_constructor_002.phpt
ext/reflection/tests/ReflectionClass_toString_001.phpt
ext/snmp/snmp.c
ext/snmp/snmp.stub.php
ext/snmp/snmp_arginfo.h
ext/snmp/tests/reflection.phpt [deleted file]
ext/spl/spl_observer.c
ext/spl/spl_observer.stub.php
ext/spl/spl_observer_arginfo.h
ext/spl/tests/multiple_iterator_001.phpt
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/password.c
ext/standard/streamsfuncs.c
ext/standard/string.c
ext/standard/tests/password/password_hash_error.phpt
ext/standard/tests/password/password_needs_rehash_error.phpt
ext/standard/tests/strings/str_replace_basic.phpt
ext/standard/tests/strings/str_replace_variation3.phpt

index 4608c1917d57def4cc446a45092026953ad715ee..8c4694e4ecf505fd9490020cbe549396dd1abaea 100644 (file)
@@ -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
index ffc4eb5018646253c74d13e0b12f8175ea5b5ffc..e0531bcc20b27bc97842a47ca5d6324efc10d00e 100644 (file)
@@ -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)
index 44a2bb15ff37f5740d4a3186045c6ecb7166038d..a90fc4caaa327d926f6e162866123b13a4885591 100644 (file)
@@ -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();
index bf5e631ba4b4fc3c3b03686d2926ce4575938014..7662004f304bd0267b06be41929bab1e1346942d 100644 (file)
@@ -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 {}
 
index cdead236438ed31d0ecc373411a4df95f8230d8d..3917187a5cc2d6c86db9cb5ca3614a0141c6a290 100644 (file)
@@ -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)
index c095749b6c8f8dde6992f80c580cc4403d48403d..977e35e4c3b3e750148d65430b740d7ca6d32cc2 100644 (file)
@@ -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);
index d8851b3314129e9b1824894cef41f02d9bbd006e..e46d1405453e827863cde9e016f4c53493074609 100644 (file)
@@ -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 {}
index 078fe220cd4fe055e005287dc3795aa9a2cb6c6a..5e4cd4281c16d647c03286a8c75cfac9aab8a4d9 100644 (file)
@@ -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")
index 11b834503bd9f0dd124704aeacf3967e783cb44a..3b7c29b087ef90269c6376e0f23337abe294a3a0 100644 (file)
@@ -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();
                }
index 539520597f0b9ef06950bae3e234659f99df9f33..311e748e9b3b92cae4ad4efce58f60eccd57ba0d 100644 (file)
@@ -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 {}
 
index 00013c7a507e657ecd52f0dcd9a7a08933b8b1f2..c0ff2d75e2b25bc5443b21ce2931263a39753e25 100644 (file)
@@ -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
index 54f4b8eda2cc440274f5034f160a2b9ac537f3d1..44ff37a96202ee504dc53d9994d5dbe204823f1e 100644 (file)
@@ -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
index bb9ead8ce35198be7b81121042d644e2cced5734..00e41bfcc9f68c3b8255d6b6820c7db1df3ca5ca 100644 (file)
@@ -37,7 +37,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector, String
     Method [ <internal:Reflection, ctor> public method __construct ] {
 
       - Parameters [1] {
-        Parameter #0 [ <required> $objectOrClass ]
+        Parameter #0 [ <required> object|string $objectOrClass ]
       }
     }
 
index ab512c68d0deb6d636f65737e237618da916ecf9..e7f3076c12d8f17b08b459623487df6c1d1d33d9 100644 (file)
@@ -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;
        }
 
index 72d42e34613ae7bf698e77d4de22e87310ef4573..1b7c1ac20ef6932b1b89a4f13aa99c605e6b9b41 100644 (file)
@@ -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() {}
index 8a734fd57369315f03256c7417ec889474b32f71..5c4a0c35a8df01f85c913a38197fa998a25d770a 100644 (file)
@@ -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 (file)
index 53fc063..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
---TEST--
-Test SNMP Reflection
---SKIPIF--
-<?php if (!extension_loaded('snmp')) die ("skip no snmp extension"); ?>
---FILE--
-<?php
-
-/* ALL PHP_ME user callable methods of SNMP class should appear here */
-
-echo new reflectionmethod('snmp', '__construct');
-echo new reflectionmethod('snmp', 'close');
-echo new reflectionmethod('snmp', 'setSecurity');
-echo new reflectionmethod('snmp', 'get');
-echo new reflectionmethod('snmp', 'getnext');
-echo new reflectionmethod('snmp', 'walk');
-echo new reflectionmethod('snmp', 'set');
-echo new reflectionmethod('snmp', 'getErrno');
-echo new reflectionmethod('snmp', 'getError');
-
-
-?>
---EXPECT--
-Method [ <internal:snmp, ctor> public method __construct ] {
-
-  - Parameters [5] {
-    Parameter #0 [ <required> int $version ]
-    Parameter #1 [ <required> string $host ]
-    Parameter #2 [ <required> string $community ]
-    Parameter #3 [ <optional> int $timeout ]
-    Parameter #4 [ <optional> int $retries ]
-  }
-}
-Method [ <internal:snmp> public method close ] {
-
-  - Parameters [0] {
-  }
-}
-Method [ <internal:snmp> public method setSecurity ] {
-
-  - Parameters [7] {
-    Parameter #0 [ <required> string $sec_level ]
-    Parameter #1 [ <optional> string $auth_protocol ]
-    Parameter #2 [ <optional> string $auth_passphrase ]
-    Parameter #3 [ <optional> string $priv_protocol ]
-    Parameter #4 [ <optional> string $priv_passphrase ]
-    Parameter #5 [ <optional> string $contextName ]
-    Parameter #6 [ <optional> string $contextEngineID ]
-  }
-}
-Method [ <internal:snmp> public method get ] {
-
-  - Parameters [2] {
-    Parameter #0 [ <required> $object_id ]
-    Parameter #1 [ <optional> bool $use_orignames ]
-  }
-}
-Method [ <internal:snmp> public method getnext ] {
-
-  - Parameters [1] {
-    Parameter #0 [ <required> $object_id ]
-  }
-}
-Method [ <internal:snmp> public method walk ] {
-
-  - Parameters [4] {
-    Parameter #0 [ <required> $object_id ]
-    Parameter #1 [ <optional> bool $suffix_keys ]
-    Parameter #2 [ <optional> int $max_repetitions ]
-    Parameter #3 [ <optional> int $non_repeaters ]
-  }
-}
-Method [ <internal:snmp> public method set ] {
-
-  - Parameters [3] {
-    Parameter #0 [ <required> $object_id ]
-    Parameter #1 [ <required> $type ]
-    Parameter #2 [ <required> $value ]
-  }
-}
-Method [ <internal:snmp> public method getErrno ] {
-
-  - Parameters [0] {
-  }
-}
-Method [ <internal:snmp> public method getError ] {
-
-  - Parameters [0] {
-  }
-}
index eaad4db815c115ec396709e8789906b7509b7b65..3f134b77dbad1540839334deec2545ff91bd21ff 100644 (file)
@@ -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);
+       }
 }
 /* }}} */
 
index e399b13c988088c29a94bc9556ce33f016c6eba5..475f3b8dc7210ac1ecd831236123fff754bdb14c 100644 (file)
@@ -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) {}
index 3c08a442685536f4f989538ecc3f6ed741e5e35b..eed972b2830e4d0949d1993964d2135a48ab2105 100644 (file)
@@ -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)
index 56a08da272dd6e60e6dd3582d9f78f6fa66c8e45..7f2b971b556e9a9010cfeaa16f8c0bd0d76fc419 100644 (file)
@@ -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 --
index 73a82b627d7c32d4bfbe6c0cd1470c6ac2fb0fcf..75819c7fb556b6efe395834cd110f419f0097eb2 100755 (executable)
@@ -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 {}
index 31200dbb92d3f2a0b26b3f0ded9bdd121078d1ff..9d13b25b855bd10fa1d2e2932cea4ce587f93181 100755 (executable)
@@ -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()
 
index de21569a44c8accb8364b5709924b4a157bb15ed..687a780d1d556f2f022a10e27f43aa8939f336df 100644 (file)
@@ -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();
        }
 
index 0bc475498f3962294b1138221f2a3dfca9c5d2a3..f56f52930cbfb024d6e8999534cb1ea2f44041a3 100644 (file)
@@ -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();
index bdaaeea47f66618e2664afe4f8e8f588d23dedc4..5631ce4ac0e454c2c19255a2580440556166b9ed 100644 (file)
@@ -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);
index 0dc056ea34b216a1ca4e109fc15392a75d1fc03d..ddb5793c815c8821f8e39569a71fbd33dc669035 100644 (file)
@@ -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
index 0b64b0c82ee38bf8bf00f8d4d77e63e525cbe754..aef86ee1247c8783d219a185acd167704f3cc118 100644 (file)
@@ -2,7 +2,6 @@
 Test error operation of password_needs_rehash()
 --FILE--
 <?php
-//-=-=-=-
 
 try {
     var_dump(password_needs_rehash(''));
@@ -10,7 +9,11 @@ try {
     echo $e->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!
index bbabf198ee1d1e2ed96d08bdc4cd733f63105278..4dfbd098efc613ea36224bba5360a3c2f6511d03 100644 (file)
@@ -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)
index 3c0562615a755a7decd4d887daebb5252c826f77..f08d8c7dc1bae93e1f5236eafaeabf721cce124f 100644 (file)
@@ -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