]> granicus.if.org Git - php/commitdiff
Promote a few forgotten warnings to exceptions
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 25 Sep 2020 08:18:12 +0000 (10:18 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 25 Sep 2020 10:08:15 +0000 (12:08 +0200)
Closes GH-6211

18 files changed:
ext/date/php_date.c
ext/date/tests/date_sunrise_and_sunset_error.phpt [new file with mode: 0644]
ext/fileinfo/fileinfo.c
ext/fileinfo/tests/bug61964-mb.phpt
ext/fileinfo/tests/bug61964.phpt
ext/fileinfo/tests/bug68996.phpt
ext/fileinfo/tests/bug71527-mb.phpt
ext/fileinfo/tests/bug71527.phpt
ext/fileinfo/tests/finfo_open_001.phpt
ext/fileinfo/tests/finfo_open_error.phpt
ext/mysqli/mysqli.c
ext/mysqli/mysqli_api.c
ext/mysqli/tests/mysqli_commit_oo.phpt
ext/mysqli/tests/mysqli_fetch_array.phpt
ext/mysqli/tests/mysqli_fetch_array_oo.phpt
ext/mysqli/tests/mysqli_stmt_bind_param.phpt
ext/mysqlnd/mysqlnd_connection.c
ext/xsl/xsltprocessor.c

index 88431a22ea205bb19fcab060199d7140cfc365c7..8c0f5a62b100c2a28d23f11ce5c28b151c971bc4 100644 (file)
@@ -4501,8 +4501,8 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su
                retformat != SUNFUNCS_RET_STRING &&
                retformat != SUNFUNCS_RET_DOUBLE)
        {
-               php_error_docref(NULL, E_WARNING, "Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE");
-               RETURN_FALSE;
+               zend_argument_value_error(2, "must be one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, or SUNFUNCS_RET_DOUBLE");
+               RETURN_THROWS();
        }
        altitude = 90 - zenith;
 
diff --git a/ext/date/tests/date_sunrise_and_sunset_error.phpt b/ext/date/tests/date_sunrise_and_sunset_error.phpt
new file mode 100644 (file)
index 0000000..4505439
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Test error condition of date_sunrise() and date_sunset()
+--FILE--
+<?php
+
+try {
+    date_sunrise(time(), 3);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+try {
+    date_sunset(time(), 4);
+} catch (ValueError $exception) {
+    echo $exception->getMessage() . "\n";
+}
+
+?>
+--EXPECT--
+date_sunrise(): Argument #2 ($returnFormat) must be one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, or SUNFUNCS_RET_DOUBLE
+date_sunset(): Argument #2 ($returnFormat) must be one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, or SUNFUNCS_RET_DOUBLE
index 2538171f25bee3e1a54d7335f76a9b5db4239967..1b26736ad0c4547e9bb655a0285b5f47133c618c 100644 (file)
@@ -71,8 +71,8 @@ static inline finfo_object *php_finfo_fetch_object(zend_object *obj) {
        finfo_object *obj = Z_FINFO_P(object); \
        finfo = obj->ptr; \
        if (!finfo) { \
-               php_error_docref(NULL, E_WARNING, "The invalid fileinfo object."); \
-               RETURN_FALSE; \
+               zend_throw_error(NULL, "Invalid finfo object"); \
+               RETURN_THROWS(); \
        } \
 }
 
@@ -270,7 +270,7 @@ PHP_FUNCTION(finfo_open)
        }
 
        if (magic_load(finfo->magic, file) == -1) {
-               php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file);
+               php_error_docref(NULL, E_WARNING, "Failed to load magic database at \"%s\"", file);
                magic_close(finfo->magic);
                efree(finfo);
                if (object) {
@@ -382,7 +382,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
 
                magic = magic_open(MAGIC_MIME_TYPE);
                if (magic_load(magic, NULL) == -1) {
-                       php_error_docref(NULL, E_WARNING, "Failed to load magic database.");
+                       php_error_docref(NULL, E_WARNING, "Failed to load magic database");
                        goto common;
                }
        } else if (object) {
index 9187393554eb613a7f3b9398a6a11747619a3343..1142ad7eeda29916032764c05fa3ca2f8026f788 100644 (file)
@@ -58,5 +58,5 @@ Warning: finfo_open(): offset `a' invalid in %sbug61964-mb.php on line %d
 
 Warning: finfo_open(): offset `b' invalid in %sbug61964-mb.php on line %d
 
-Warning: finfo_open(): Failed to load magic database at '%sbug61964-mb'. in %sbug61964-mb.php on line %d
+Warning: finfo_open(): Failed to load magic database at "%sbug61964-mb" in %sbug61964-mb.php on line %d
 DONE: testing dir with files
index 24cf3bec8c8070c7b1194a216bde895c7694e858..ecb12fe75214d852574f1b6fbbe95626575d5231 100644 (file)
@@ -58,5 +58,5 @@ Warning: finfo_open(): offset `a' invalid in %sbug61964.php on line %d
 
 Warning: finfo_open(): offset `b' invalid in %sbug61964.php on line %d
 
-Warning: finfo_open(): Failed to load magic database at '%sbug61964'. in %sbug61964.php on line %d
+Warning: finfo_open(): Failed to load magic database at "%sbug61964" in %sbug61964.php on line %d
 DONE: testing dir with files
index aabd2670bdc08f8549a5b2ede19e0d395b15a3eb..2535f5e455857a11ee4ce18ca872d637426159ff 100644 (file)
@@ -14,4 +14,4 @@ finfo_open(FILEINFO_MIME_TYPE, "\xfc\x63");
 <br />
 <b>Warning</b>:  finfo_open(%s�c): Failed to open stream: No such file or directory in <b>%sbug68996.php</b> on line <b>%d</b><br />
 <br />
-<b>Warning</b>:  finfo_open(): Failed to load magic database at '%s�c'. in <b>%sbug68996.php</b> on line <b>%d</b><br />
+<b>Warning</b>:  finfo_open(): Failed to load magic database at &quot;%s�c&quot; in <b>%s</b> on line <b>%d</b><br />
index ea32a8122a923314434269ed675e09d98720942e..0240ce3303eb9a5c32182c945623b2f68272506f 100644 (file)
@@ -12,5 +12,5 @@ USE_ZEND_ALLOC=0
     var_dump($finfo);
 ?>
 --EXPECTF--
-Warning: finfo_open(): Failed to load magic database at '%sbug71527私はガラスを食べられます.magic'. in %sbug71527-mb.php on line %d
+Warning: finfo_open(): Failed to load magic database at "%sbug71527私はガラスを食べられます.magic" in %sbug71527-mb.php on line %d
 bool(false)
index 9a00c4f32b83d7130fff3d4f8061526443cafc84..3a536266fcf2a2fee40345140d4af241e15f7066 100644 (file)
@@ -12,5 +12,5 @@ USE_ZEND_ALLOC=0
     var_dump($finfo);
 ?>
 --EXPECTF--
-Warning: finfo_open(): Failed to load magic database at '%sbug71527.magic'. in %sbug71527.php on line %d
+Warning: finfo_open(): Failed to load magic database at "%sbug71527.magic" in %sbug71527.php on line %d
 bool(false)
index b2285dd35c4dfbc8ce554c70497d17875bfcdabb..ef36bc21f08e825a5fb7672b1bbb3e41fe740bfe 100644 (file)
@@ -27,19 +27,19 @@ Warning: finfo_open(%s123): Failed to open stream: No such file or directory in
 
 Warning: finfo_open(%s123): Failed to open stream: No such file or directory in %s on line %d
 
-Warning: finfo_open(): Failed to load magic database at '%s123'. in %s on line %d
+Warning: finfo_open(): Failed to load magic database at "%s123" in %s on line %d
 bool(false)
 
 Warning: finfo_open(%s1): Failed to open stream: No such file or directory in %s on line %d
 
 Warning: finfo_open(%s1): Failed to open stream: No such file or directory in %s on line %d
 
-Warning: finfo_open(): Failed to load magic database at '%s1'. in %s on line %d
+Warning: finfo_open(): Failed to load magic database at "%s1" in %s on line %d
 bool(false)
 
 Warning: finfo_open(%sinexistent): Failed to open stream: No such file or directory in %s on line %d
 
 Warning: finfo_open(%sinexistent): Failed to open stream: No such file or directory in %s on line %d
 
-Warning: finfo_open(): Failed to load magic database at '%sinexistent'. in %s on line %d
+Warning: finfo_open(): Failed to load magic database at "%sinexistent" in %s on line %d
 bool(false)
index b079de682d80f2a49273751c2f67afeecc8ce24f..881c26f6648276d266baa8d39551558a96afda14 100644 (file)
@@ -31,7 +31,7 @@ Warning: finfo_open(%sfoobarfile): Failed to open stream: No such file or direct
 
 Warning: finfo_open(%sfoobarfile): Failed to open stream: No such file or directory in %sfinfo_open_error.php on line %d
 
-Warning: finfo_open(): Failed to load magic database at '%sfoobarfile'. in %sfinfo_open_error.php on line %d
+Warning: finfo_open(): Failed to load magic database at "%sfoobarfile" in %sfinfo_open_error.php on line %d
 bool(false)
 
 Warning: finfo_open(): using regular magic file `%smagic' in %sfinfo_open_error.php on line %d
index 9eb1885ea6ffbddd888ad60c8f64cac86d52e25e..05ffffa926a106fe19bcdd99691c0af93d18d509 100644 (file)
@@ -47,6 +47,8 @@ static PHP_GINIT_FUNCTION(mysqli);
        } \
 }
 
+#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
+
 static HashTable classes;
 static zend_object_handlers mysqli_object_handlers;
 static zend_object_handlers mysqli_object_driver_handlers;
@@ -1168,8 +1170,8 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
 
        if (fetchtype < MYSQLI_ASSOC || fetchtype > MYSQLI_BOTH) {
-               php_error_docref(NULL, E_WARNING, "The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH");
+               RETURN_THROWS();
        }
 
        php_mysqli_fetch_into_hash_aux(return_value, result, fetchtype);
index 928031f82e78d4327f4a9d457425a95eecf86bbe..91915809428a0dd9cb40d28ba9f922f68e0e0e2b 100644 (file)
@@ -93,7 +93,7 @@ mysqli_escape_string_for_tx_name_in_comment(const char * const name)
                        {
                                *p_copy++ = v;
                        } else if (warned == FALSE) {
-                               php_error_docref(NULL, E_WARNING, "Transaction name truncated. Must be only [0-9A-Za-z\\-_=]+");
+                               php_error_docref(NULL, E_WARNING, "Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, \"\\\", \"-\", \"_\", and \"=\" characters");
                                warned = TRUE;
                        }
                        ++p_orig;
@@ -230,7 +230,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a
                                break;
 
                        default:
-                               php_error_docref(NULL, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[ofs], i + num_extra_args + 1);
+                               zend_argument_value_error(num_extra_args, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers");
                                rc = 1;
                                goto end_1;
                }
@@ -292,8 +292,7 @@ int mysqli_stmt_bind_param_do_bind(MY_STMT *stmt, unsigned int num_vars, zval *a
                                type = MYSQL_TYPE_VAR_STRING;
                                break;
                        default:
-                               /* We count parameters from 1 */
-                               php_error_docref(NULL, E_WARNING, "Undefined fieldtype %c (parameter %d)", types[i], i + num_extra_args + 1);
+                               zend_argument_value_error(num_extra_args, "must only contain the \"b\", \"d\", \"i\", \"s\" type specifiers");
                                ret = FAIL;
                                mysqlnd_stmt_free_param_bind(stmt->stmt, params);
                                goto end;
index 6377fdf5a91c8efd64053d6cc467742c680a5e61..e4cfbe47943adf91ce2e695f9a2a25de9c364925 100644 (file)
@@ -76,15 +76,13 @@ if (!have_innodb($link))
     if (!$mysqli->commit(0 , "tx_name0123")) {
         printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error);
     }
-    if (!$mysqli->commit(0 , "*/ nonsense")) {
-        printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error);
-    }
-    if (!$mysqli->commit(0 , "tx_name ulf вендел")) {
-        printf("[014] [%d] %s\n", $mysqli->errno, $mysqli->error);
-    }
-    if (!$mysqli->commit(0 , "tx_name \t\n\r\b")) {
-        printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error);
-    }
+
+    var_dump($mysqli->commit(0 , "*/ nonsense"));
+
+    var_dump($mysqli->commit(0 , "tx_name ulf вендел"));
+
+    var_dump($mysqli->commit(0 , "tx_name \t\n\r\b"));
+
     if (!$mysqli->commit(MYSQLI_TRANS_COR_AND_CHAIN | MYSQLI_TRANS_COR_NO_RELEASE , "tx_name")) {
         printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error);
     }
@@ -105,10 +103,13 @@ if (!have_innodb($link))
 --EXPECTF--
 mysqli object is not fully initialized
 
-Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
+Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
+bool(true)
 
-Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
+Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
+bool(true)
 
-Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
+Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
+bool(true)
 my_mysqli object is already closed
 done!
index c2046f1821e65587b6b7dbc0f8f914fcc038b181..044ed2de0c61f5405709356116f19fceb589d982 100644 (file)
@@ -48,15 +48,17 @@ require_once('skipifconnectfailure.inc');
         $illegal_mode = mt_rand(-10000, 10000);
     } while (in_array($illegal_mode, array(MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH)));
     // NOTE: for BC reasons with ext/mysql, ext/mysqli accepts invalid result modes.
-    $tmp = mysqli_fetch_array($res, $illegal_mode);
-    if (false !== $tmp)
-            printf("[013] Expecting boolean/false although, got %s/%s. [%d] %s\n",
-                gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
+    try {
+        mysqli_fetch_array($res, $illegal_mode);
+    } catch (ValueError $exception) {
+        echo $exception->getMessage() . "\n";
+    }
 
-    $tmp = mysqli_fetch_array($res, $illegal_mode);
-    if (false !== $tmp)
-        printf("[014] Expecting boolean/false, got %s/%s. [%d] %s\n",
-                gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
+    try {
+        mysqli_fetch_array($res, $illegal_mode);
+    } catch (ValueError $exception) {
+        echo $exception->getMessage() . "\n";
+    }
 
     mysqli_free_result($res);
 
@@ -357,9 +359,7 @@ array(11) {
   ["e"]=>
   string(1) "1"
 }
-
-Warning: mysqli_fetch_array(): The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH in %s on line %d
-
-Warning: mysqli_fetch_array(): The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH in %s on line %d
+mysqli_fetch_array(): Argument #2 ($fetchtype) must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH
+mysqli_fetch_array(): Argument #2 ($fetchtype) must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH
 mysqli_result object is already closed
 done!
index 6bf2b0f4c02df98b0cc165a690b3fb40d00c2217..599b9d0c9490dca765eb527e22c2d4ff21a8b3c6 100644 (file)
@@ -55,15 +55,17 @@ require_once('skipifconnectfailure.inc');
         $illegal_mode = mt_rand(-10000, 10000);
     } while (in_array($illegal_mode, array(MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH)));
     // NOTE: for BC reasons with ext/mysql, ext/mysqli accepts invalid result modes.
-    $tmp = $res->fetch_array($illegal_mode);
-    if (false !== $tmp)
-        printf("[013] Expecting boolean/false although, got %s/%s. [%d] %s\n",
-            gettype($tmp), $tmp, $mysqli->errno, $mysqli->error);
+    try {
+        $res->fetch_array($illegal_mode);
+    } catch (Error $exception) {
+        echo $exception->getMessage() . "\n";
+    }
 
-    $tmp = $res->fetch_array($illegal_mode);
-    if (false !== $tmp)
-        printf("[014] Expecting boolean/false, got %s/%s. [%d] %s\n",
-            gettype($tmp), $tmp, $mysqli->errno, $mysqli->error);
+    try {
+        $res->fetch_array($illegal_mode);
+    } catch (Error $exception) {
+        echo $exception->getMessage() . "\n";
+    }
 
     $res->free_result();
 
@@ -353,9 +355,7 @@ array(11) {
   ["e"]=>
   string(1) "1"
 }
-
-Warning: mysqli_result::fetch_array(): The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH in %s on line %d
-
-Warning: mysqli_result::fetch_array(): The result type should be either MYSQLI_NUM, MYSQLI_ASSOC or MYSQLI_BOTH in %s on line %d
+mysqli_result::fetch_array(): Argument #1 ($result_type) must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH
+mysqli_result::fetch_array(): Argument #1 ($result_type) must be one of MYSQLI_NUM, MYSQLI_ASSOC, or MYSQLI_BOTH
 mysqli_result object is already closed
 done!
index 237b72264675075a949709cb7d02515d243171e8..f3f11511ca181fc52b9b4abd0110bb77d0b14fb2 100644 (file)
@@ -83,16 +83,14 @@ require_once('skipifconnectfailure.inc');
     }
 
     try {
-        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "aa", $id, $label)))
-            printf("[006] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
-    } catch (\ArgumentCountError $e) {
+        mysqli_stmt_bind_param($stmt, "aa", $id, $label);
+    } catch (ValueError $e) {
         echo $e->getMessage() . \PHP_EOL;
     }
 
     try {
-        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "ia", $id, $label)))
-            printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
-    } catch (\ArgumentCountError $e) {
+        mysqli_stmt_bind_param($stmt, "ia", $id, $label);
+    } catch (ValueError $e) {
         echo $e->getMessage() . \PHP_EOL;
     }
 
@@ -414,7 +412,7 @@ require_once('skipifconnectfailure.inc');
 <?php
     require_once("clean_table.inc");
 ?>
---EXPECTF--
+--EXPECT--
 The number of variables must match the number of parameters in the prepared statement
 mysqli_stmt_bind_param(): Argument #2 ($types) cannot be empty
 The number of elements in the type definition string must match the number of bind variables
@@ -422,8 +420,6 @@ The number of variables must match the number of parameters in the prepared stat
 The number of elements in the type definition string must match the number of bind variables
 The number of variables must match the number of parameters in the prepared statement
 The number of elements in the type definition string must match the number of bind variables
-
-Warning: mysqli_stmt_bind_param(): Undefined fieldtype a (parameter 3) in %s on line %d
-
-Warning: mysqli_stmt_bind_param(): Undefined fieldtype a (parameter 4) in %s on line %d
+mysqli_stmt_bind_param(): Argument #2 ($types) must only contain the "b", "d", "i", "s" type specifiers
+mysqli_stmt_bind_param(): Argument #2 ($types) must only contain the "b", "d", "i", "s" type specifiers
 done!
index 5915e1266e5d47778339c81882c12267f1231857..35cc3f55fc0ac5291446bfa65d5737b062fac78d 100644 (file)
@@ -2054,7 +2054,7 @@ mysqlnd_escape_string_for_tx_name_in_comment(const char * const name)
                        {
                                *p_copy++ = v;
                        } else if (warned == FALSE) {
-                               php_error_docref(NULL, E_WARNING, "Transaction name truncated. Must be only [0-9A-Za-z\\-_=]+");
+                               php_error_docref(NULL, E_WARNING, "Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, \"\\\", \"-\", \"_\", and \"=\" characters");
                                warned = TRUE;
                        }
                        ++p_orig;
index deac062bfab09ff1f92099383766efbf4815b754..d900d951033cb0179f708324f03ad831b63e1ac8 100644 (file)
@@ -573,9 +573,10 @@ PHP_METHOD(XSLTProcessor, transformToDoc)
                        ce = zend_lookup_class(ret_class);
                        if (ce == NULL || !instanceof_function(ce, curce)) {
                                xmlFreeDoc(newdocp);
-                               php_error_docref(NULL, E_WARNING,
-                                       "Expecting class compatible with %s, '%s' given", ZSTR_VAL(curclass_name), ZSTR_VAL(ret_class));
-                               RETURN_FALSE;
+                               zend_argument_type_error(2, "must be a class name compatible with %s, \"%s\" given",
+                                       ZSTR_VAL(curclass_name), ZSTR_VAL(ret_class)
+                               );
+                               RETURN_THROWS();
                        }
 
                        object_init_ex(return_value, ce);