]> granicus.if.org Git - php/commitdiff
mb_convert_variables(): Make $from an array|string argument
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 13:51:04 +0000 (15:51 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Mar 2020 13:51:04 +0000 (15:51 +0200)
ext/mbstring/mbstring.c
ext/mbstring/mbstring.stub.php
ext/mbstring/mbstring_arginfo.h

index dd801a94c53b27ceadec6ee77750c2116682f399..1118200cd9cc0ffba79850aa977933042a885487 100644 (file)
@@ -3353,7 +3353,9 @@ static int mb_recursive_convert_variable(mbfl_buffer_converter *convd, zval *var
    Converts the string resource in variables to desired encoding */
 PHP_FUNCTION(mb_convert_variables)
 {
-       zval *args, *zfrom_enc;
+       zval *args;
+       zend_string *from_enc_str;
+       HashTable *from_enc_ht;
        mbfl_string string, result;
        const mbfl_encoding *from_encoding, *to_encoding;
        mbfl_encoding_detector *identd;
@@ -3365,9 +3367,11 @@ PHP_FUNCTION(mb_convert_variables)
        char *to_enc;
        int recursion_error = 0;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz+", &to_enc, &to_enc_len, &zfrom_enc, &args, &argc) == FAILURE) {
-               RETURN_THROWS();
-       }
+       ZEND_PARSE_PARAMETERS_START(3, -1)
+               Z_PARAM_STRING(to_enc, to_enc_len)
+               Z_PARAM_STR_OR_ARRAY_HT(from_enc_str, from_enc_ht)
+               Z_PARAM_VARIADIC('+', args, argc)
+       ZEND_PARSE_PARAMETERS_END();
 
        /* new encoding */
        to_encoding = mbfl_name2encoding(to_enc);
@@ -3384,22 +3388,14 @@ PHP_FUNCTION(mb_convert_variables)
        string.no_language = MBSTRG(language);
 
        /* pre-conversion encoding */
-       elist = NULL;
-       elistsz = 0;
-       switch (Z_TYPE_P(zfrom_enc)) {
-               case IS_ARRAY:
-                       if (php_mb_parse_encoding_array(Z_ARRVAL_P(zfrom_enc), &elist, &elistsz, 0) == FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       break;
-               default:
-                       if (!try_convert_to_string(zfrom_enc)) {
-                               RETURN_THROWS();
-                       }
-                       if (php_mb_parse_encoding_list(Z_STRVAL_P(zfrom_enc), Z_STRLEN_P(zfrom_enc), &elist, &elistsz, 0) == FAILURE) {
-                               RETURN_FALSE;
-                       }
-                       break;
+       if (from_enc_ht) {
+               if (php_mb_parse_encoding_array(from_enc_ht, &elist, &elistsz, 0) == FAILURE) {
+                       RETURN_FALSE;
+               }
+       } else {
+               if (php_mb_parse_encoding_list(ZSTR_VAL(from_enc_str), ZSTR_LEN(from_enc_str), &elist, &elistsz, 0) == FAILURE) {
+                       RETURN_FALSE;
+               }
        }
 
        if (elistsz == 0) {
index 99211be0e3deb5b584d027d8cad0fddfbf12b2de..67d8468f430098d76d4bfeac93c2fe9a34964f78 100644 (file)
@@ -69,8 +69,7 @@ function mb_decode_mimeheader(string $string): string|false {}
 
 function mb_convert_kana(string $str, string $option = UNKNOWN, string $encoding = UNKNOWN): string|false {}
 
-/** @param array|string $from */
-function mb_convert_variables(string $to, $from, &$var, &...$vars): string|false {}
+function mb_convert_variables(string $to, array|string $from, &$var, &...$vars): string|false {}
 
 function mb_encode_numericentity(string $string, array $convmap, string $encoding = UNKNOWN, bool $is_hex = false): string|false {}
 
index ff1da3c55e7cbb245c7c538c0f3e59677f1c2afa..bb902af837d9933954ae100faf37494ac6e98728 100644 (file)
@@ -155,7 +155,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_convert_variables, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
        ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0)
-       ZEND_ARG_INFO(0, from)
+       ZEND_ARG_TYPE_MASK(0, from, MAY_BE_ARRAY|MAY_BE_STRING)
        ZEND_ARG_INFO(1, var)
        ZEND_ARG_VARIADIC_INFO(1, vars)
 ZEND_END_ARG_INFO()