]> granicus.if.org Git - php/commitdiff
Promote empty string warning to ValueError in mb_ord()
authorGeorge Peter Banyard <girgias@php.net>
Thu, 2 Apr 2020 16:35:20 +0000 (18:35 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Thu, 2 Apr 2020 20:39:59 +0000 (22:39 +0200)
ext/mbstring/mbstring.c
ext/mbstring/tests/mb_ord.phpt

index 4215d7b7a4934723b6a762992272a00b00f65d1e..1a5f512765ea02657e1db92e993dffd72ff3cdf5 100644 (file)
@@ -4335,6 +4335,8 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
        const mbfl_encoding *enc;
        enum mbfl_no_encoding no_enc;
 
+       ZEND_ASSERT(str_len > 0);
+
        enc = php_mb_get_encoding(enc_name, enc_name_arg_num);
        if (!enc) {
                return -2;
@@ -4346,11 +4348,6 @@ static inline zend_long php_mb_ord(const char *str, size_t str_len, zend_string
                return -2;
        }
 
-       if (str_len == 0) {
-               php_error_docref(NULL, E_WARNING, "Empty string");
-               return -1;
-       }
-
        {
                mbfl_wchar_device dev;
                mbfl_convert_filter *filter;
@@ -4396,6 +4393,11 @@ PHP_FUNCTION(mb_ord)
                Z_PARAM_STR(enc)
        ZEND_PARSE_PARAMETERS_END();
 
+       if (str_len == 0) {
+               zend_argument_value_error(1, "must not be empty");
+               RETURN_THROWS();
+       }
+
        cp = php_mb_ord(str, str_len, enc, 2);
 
        if (0 > cp) {
index 5c7fdf3168c1b17bd77c85c87af8f19bcdb0b946..56e8d4a8140cd9629fd68989d70893d011b554a3 100644 (file)
@@ -50,15 +50,13 @@ try {
 } catch (\ValueError $e) {
     echo $e->getMessage() . \PHP_EOL;
 }
-;
+
 ?>
---EXPECTF--
+--EXPECT--
 bool(true)
 bool(true)
 bool(true)
-
-Warning: mb_ord(): Empty string in %s on line %d
-bool(false)
+mb_ord(): Argument #1 ($str) must not be empty
 mb_ord(): Argument #2 ($encoding) must be a valid encoding, "typo" given
 mb_ord() does not support the "pass" encoding
 mb_ord() does not support the "JIS" encoding