]> granicus.if.org Git - php/commitdiff
mb_detect_order(): Use proper array|string argument
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 14:26:28 +0000 (16:26 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 14:26:28 +0000 (16:26 +0200)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.stub.php
ext/mbstring/mbstring_arginfo.h

index a0f4a0b24dd286ec5f452711f473c1e6131c00a8..4f698a7a473645a5725b5053d3a19dc1c78f21d6 100644 (file)
@@ -1530,13 +1530,15 @@ PHP_FUNCTION(mb_http_output)
    Sets the current detect_order or Return the current detect_order as a array */
 PHP_FUNCTION(mb_detect_order)
 {
-       zval *arg1 = NULL;
+       zend_string *order_str = NULL;
+       HashTable *order_ht = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg1) == FAILURE) {
-               RETURN_THROWS();
-       }
+       ZEND_PARSE_PARAMETERS_START(0, 1)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_STR_OR_ARRAY_HT(order_str, order_ht)
+       ZEND_PARSE_PARAMETERS_END();
 
-       if (!arg1) {
+       if (!order_str && !order_ht) {
                size_t i;
                size_t n = MBSTRG(current_detect_order_list_size);
                const mbfl_encoding **entry = MBSTRG(current_detect_order_list);
@@ -1546,22 +1548,16 @@ PHP_FUNCTION(mb_detect_order)
                        entry++;
                }
        } else {
-               const mbfl_encoding **list = NULL;
-               size_t size = 0;
-               switch (Z_TYPE_P(arg1)) {
-                       case IS_ARRAY:
-                               if (FAILURE == php_mb_parse_encoding_array(Z_ARRVAL_P(arg1), &list, &size)) {
-                                       RETURN_FALSE;
-                               }
-                               break;
-                       default:
-                               if (!try_convert_to_string(arg1)) {
-                                       RETURN_THROWS();
-                               }
-                               if (FAILURE == php_mb_parse_encoding_list(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), &list, &size, 0)) {
-                                       RETURN_FALSE;
-                               }
-                               break;
+               const mbfl_encoding **list;
+               size_t size;
+               if (order_ht) {
+                       if (FAILURE == php_mb_parse_encoding_array(order_ht, &list, &size)) {
+                               RETURN_FALSE;
+                       }
+               } else {
+                       if (FAILURE == php_mb_parse_encoding_list(ZSTR_VAL(order_str), ZSTR_LEN(order_str), &list, &size, 0)) {
+                               RETURN_FALSE;
+                       }
                }
 
                if (size == 0) {
index 85f9305cc00dc6e57ad4046a19b441a98515c2bb..5598aa8c129c768218ee5b2b424bad36cfcfed6b 100644 (file)
@@ -8,7 +8,7 @@ function mb_http_input(string $type = UNKNOWN): array|string|false {}
 
 function mb_http_output(string $encoding = UNKNOWN): string|bool {}
 
-function mb_detect_order($encoding = UNKNOWN): array|bool {}
+function mb_detect_order(array|string $encoding = UNKNOWN): array|bool {}
 
 /** @param string|int $substchar */
 function mb_substitute_character($substchar = UNKNOWN): string|int|bool {}
index 73da9874d9ba1070b240fd63fd764a30b25fed96..8d37ae1cbe4a0b4423d9af5d572ea07a51166123 100644 (file)
@@ -15,7 +15,7 @@ ZEND_END_ARG_INFO()
 #define arginfo_mb_http_output arginfo_mb_internal_encoding
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_detect_order, 0, 0, MAY_BE_ARRAY|MAY_BE_BOOL)
-       ZEND_ARG_INFO(0, encoding)
+       ZEND_ARG_TYPE_MASK(0, encoding, MAY_BE_ARRAY|MAY_BE_STRING)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_substitute_character, 0, 0, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_BOOL)