]> granicus.if.org Git - php/commitdiff
mb_convert_encoding(): Make $input a proper array|string arg
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 13:41:55 +0000 (15:41 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 13:41:55 +0000 (15:41 +0200)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.stub.php
ext/mbstring/mbstring_arginfo.h

index 62c71b19ce91e0d870721737eab4b9910690a6ba..dd801a94c53b27ceadec6ee77750c2116682f399 100644 (file)
@@ -2773,17 +2773,16 @@ MBSTRING_API HashTable *php_mb_convert_encoding_recursive(HashTable *input, cons
    Returns converted string in desired encoding */
 PHP_FUNCTION(mb_convert_encoding)
 {
-       zval *input;
        zend_string *to_encoding_name;
-       zend_string *from_encodings_str = NULL;
-       HashTable *from_encodings_ht = NULL;
+       zend_string *input_str, *from_encodings_str = NULL;
+       HashTable *input_ht, *from_encodings_ht = NULL;
        const mbfl_encoding *to_encoding;
        const mbfl_encoding **from_encodings;
        size_t num_from_encodings;
        zend_bool free_from_encodings;
 
        ZEND_PARSE_PARAMETERS_START(2, 3)
-               Z_PARAM_ZVAL(input)
+               Z_PARAM_STR_OR_ARRAY_HT(input_str, input_ht)
                Z_PARAM_STR(to_encoding_name)
                Z_PARAM_OPTIONAL
                Z_PARAM_STR_OR_ARRAY_HT(from_encodings_str, from_encodings_ht)
@@ -2794,12 +2793,6 @@ PHP_FUNCTION(mb_convert_encoding)
                RETURN_FALSE;
        }
 
-       if (Z_TYPE_P(input) != IS_STRING && Z_TYPE_P(input) != IS_ARRAY) {
-               if (!try_convert_to_string(input)) {
-                       RETURN_THROWS();
-               }
-       }
-
        if (from_encodings_ht) {
                if (php_mb_parse_encoding_array(from_encodings_ht, &from_encodings, &num_from_encodings, 0) == FAILURE) {
                        RETURN_FALSE;
@@ -2822,11 +2815,11 @@ PHP_FUNCTION(mb_convert_encoding)
                RETURN_FALSE;
        }
 
-       if (Z_TYPE_P(input) == IS_STRING) {
+       if (input_str) {
                /* new encoding */
                size_t size;
                char *ret = php_mb_convert_encoding(
-                       Z_STRVAL_P(input), Z_STRLEN_P(input),
+                       ZSTR_VAL(input_str), ZSTR_LEN(input_str),
                        to_encoding, from_encodings, num_from_encodings, &size);
                if (ret != NULL) {
                        // TODO: avoid reallocation ???
@@ -2838,7 +2831,7 @@ PHP_FUNCTION(mb_convert_encoding)
        } else {
                HashTable *tmp;
                tmp = php_mb_convert_encoding_recursive(
-                       Z_ARRVAL_P(input), to_encoding, from_encodings, num_from_encodings);
+                       input_ht, to_encoding, from_encodings, num_from_encodings);
                RETVAL_ARR(tmp);
        }
 
index 11eb631c865c766d86d110daf1198ce98b0768fa..99211be0e3deb5b584d027d8cad0fddfbf12b2de 100644 (file)
@@ -48,8 +48,7 @@ function mb_strwidth(string $str, string $encoding = UNKNOWN): int|false {}
 
 function mb_strimwidth(string $str, int $start, int $width, string $trimmarker = UNKNOWN, string $encoding = UNKNOWN): string|false {}
 
-/** @param array|string $str */
-function mb_convert_encoding($str, string $to, array|string $from = UNKNOWN): array|string|false {}
+function mb_convert_encoding(array|string $str, string $to, array|string $from = UNKNOWN): array|string|false {}
 
 function mb_convert_case(string $sourcestring, int $mode, ?string $encoding = null): string|false {}
 
index 5752d93ffe9d629d38a63a7fd8b12f43faf3d4f0..ff1da3c55e7cbb245c7c538c0f3e59677f1c2afa 100644 (file)
@@ -104,7 +104,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strimwidth, 0, 3, MAY_BE_STRI
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_convert_encoding, 0, 2, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE)
-       ZEND_ARG_INFO(0, str)
+       ZEND_ARG_TYPE_MASK(0, str, MAY_BE_ARRAY|MAY_BE_STRING)
        ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0)
        ZEND_ARG_TYPE_MASK(0, from, MAY_BE_ARRAY|MAY_BE_STRING)
 ZEND_END_ARG_INFO()