]> granicus.if.org Git - php/commitdiff
Promote warnings to Error in MySQLi extension
authorGeorge Peter Banyard <girgias@php.net>
Fri, 3 Jul 2020 11:43:29 +0000 (13:43 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Tue, 15 Sep 2020 17:12:02 +0000 (19:12 +0200)
Closes GH-5803

38 files changed:
ext/mysqli/mysqli.c
ext/mysqli/mysqli.stub.php
ext/mysqli/mysqli_api.c
ext/mysqli/mysqli_arginfo.h
ext/mysqli/mysqli_nonapi.c
ext/mysqli/tests/bug55582.phpt
ext/mysqli/tests/bug74595.phpt [deleted file]
ext/mysqli/tests/connect.inc
ext/mysqli/tests/mysqli_begin_transaction.phpt
ext/mysqli/tests/mysqli_data_seek.phpt
ext/mysqli/tests/mysqli_data_seek_oo.phpt
ext/mysqli/tests/mysqli_fetch_all.phpt
ext/mysqli/tests/mysqli_fetch_all_oo.phpt
ext/mysqli/tests/mysqli_fetch_field_direct.phpt
ext/mysqli/tests/mysqli_fetch_field_direct_oo.phpt
ext/mysqli/tests/mysqli_field_seek.phpt
ext/mysqli/tests/mysqli_field_tell.phpt
ext/mysqli/tests/mysqli_kill.phpt
ext/mysqli/tests/mysqli_num_rows.phpt
ext/mysqli/tests/mysqli_poll.phpt
ext/mysqli/tests/mysqli_query.phpt
ext/mysqli/tests/mysqli_release_savepoint.phpt
ext/mysqli/tests/mysqli_report.phpt
ext/mysqli/tests/mysqli_result_invalid_mode.phpt
ext/mysqli/tests/mysqli_savepoint.phpt
ext/mysqli/tests/mysqli_stmt_attr_get.phpt
ext/mysqli/tests/mysqli_stmt_attr_set.phpt
ext/mysqli/tests/mysqli_stmt_bind_param.phpt
ext/mysqli/tests/mysqli_stmt_bind_result.phpt
ext/mysqli/tests/mysqli_stmt_data_seek.phpt
ext/mysqli/tests/mysqli_stmt_execute_stored_proc_out.phpt
ext/mysqli/tests/mysqli_stmt_field_count.phpt
ext/mysqli/tests/mysqli_stmt_get_result_metadata.phpt
ext/mysqli/tests/mysqli_stmt_get_result_seek.phpt
ext/mysqli/tests/mysqli_stmt_send_long_data.phpt
ext/mysqli/tests/mysqli_store_result_copy.phpt
ext/mysqli/tests/mysqli_use_result.phpt
ext/opcache/Optimizer/zend_func_info.c

index b2f85bc147df0dd721a2aab200bf44a163ff8503..e056ceba2dabd7a25fb8fba4b1fecb6bb85974ff 100644 (file)
@@ -384,8 +384,7 @@ static int mysqli_object_has_property(zend_object *object, zend_string *name, in
                                }
                                break;
                        }
-                       default:
-                               php_error_docref(NULL, E_WARNING, "Invalid value for has_set_exists");
+                       EMPTY_SWITCH_DEFAULT_CASE();
                }
        } else {
                ret = zend_std_has_property(object, name, has_set_exists, cache_slot);
@@ -1035,7 +1034,8 @@ PHP_METHOD(mysqli_result, __construct)
                        result = mysql_use_result(mysql->mysql);
                        break;
                default:
-                       php_error_docref(NULL, E_WARNING, "Invalid value for resultmode");
+                       zend_argument_value_error(2, "must be either MYSQLI_STORE_RESULT or MYSQLI_USE_RESULT");
+                       RETURN_THROWS();
        }
 
        if (!result) {
@@ -1052,7 +1052,7 @@ PHP_METHOD(mysqli_result, __construct)
 PHP_METHOD(mysqli_result, getIterator)
 {
        if (zend_parse_parameters_none() == FAILURE) {
-               return;
+               RETURN_THROWS();
        }
 
        zend_create_internal_iterator_zval(return_value, ZEND_THIS);
@@ -1130,6 +1130,7 @@ void php_mysqli_fetch_into_hash_aux(zval *return_value, MYSQL_RES * result, zend
 }
 /* }}} */
 
+/* TODO Split this up */
 /* {{{ php_mysqli_fetch_into_hash */
 void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags, int into_object)
 {
index 940f3c4fcc749babe842c1879c1f7ef571c8c919..de74bba8e128f684965114b50e37a47ce5b7f45a 100644 (file)
@@ -164,7 +164,7 @@ class mysqli
      * @return mysqli_result|bool
      * @alias mysqli_query
      */
-    public function query(string $query, int $resultmode = MYSQLI_STORE_RESULT) {}
+    public function query(string $query, int $result_mode = MYSQLI_STORE_RESULT) {}
 
     /**
      * @return bool
@@ -301,7 +301,7 @@ class mysqli
 
 class mysqli_result implements IteratorAggregate
 {
-    public function __construct(object $mysqli_link, int $resmode = MYSQLI_STORE_RESULT) {}
+    public function __construct(object $mysqli_link, int $result_mode = MYSQLI_STORE_RESULT) {}
 
     /**
      * @return void
@@ -421,7 +421,7 @@ class mysqli_stmt
     public function close() {}
 
     /**
-     * @return bool|null
+     * @return void
      * @alias mysqli_stmt_data_seek
      */
     public function data_seek(int $offset) {}
@@ -641,7 +641,7 @@ function mysqli_prepare(mysqli $mysqli_link, string $query): mysqli_stmt|false {
 
 function mysqli_report(int $flags): bool {}
 
-function mysqli_query(mysqli $mysqli_link, string $query, int $resultmode = MYSQLI_STORE_RESULT): mysqli_result|bool {}
+function mysqli_query(mysqli $mysqli_link, string $query, int $result_mode = MYSQLI_STORE_RESULT): mysqli_result|bool {}
 
 function mysqli_real_connect(
     mysqli $mysqli_link,
@@ -672,7 +672,7 @@ function mysqli_set_charset(mysqli $mysqli_link, string $charset): bool {}
 
 function mysqli_stmt_affected_rows(mysqli_stmt $mysql_stmt): int|string {}
 
-function mysqli_stmt_attr_get(mysqli_stmt $mysql_stmt, int $attr): int|false {}
+function mysqli_stmt_attr_get(mysqli_stmt $mysql_stmt, int $attr): int {}
 
 function mysqli_stmt_attr_set(mysqli_stmt $mysql_stmt, int $attr, int $mode_in): bool {}
 
@@ -682,7 +682,7 @@ function mysqli_stmt_bind_result(mysqli_stmt $mysql_stmt, mixed &...$vars): bool
 
 function mysqli_stmt_close(mysqli_stmt $mysql_stmt): bool {}
 
-function mysqli_stmt_data_seek(mysqli_stmt $mysql_stmt, int $offset): ?bool {}
+function mysqli_stmt_data_seek(mysqli_stmt $mysql_stmt, int $offset): void {}
 
 function mysqli_stmt_errno(mysqli_stmt $mysql_stmt): int {}
 
index 3f89e838fd8944e7724b377db6c08272c061a80f..88e6e91cd151aac46e7f0a93f84bce8a713b78a1 100644 (file)
@@ -31,6 +31,8 @@
 #include "mysqli_priv.h"
 #include "ext/mysqlnd/mysql_float_to_double.h"
 
+#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
+
 
 #ifndef MYSQLI_USE_MYSQLND
 /* {{{ mysqli_tx_cor_options_to_string */
@@ -324,19 +326,19 @@ PHP_FUNCTION(mysqli_stmt_bind_param)
        MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
 
        if (!types_len) {
-               php_error_docref(NULL, E_WARNING, "Invalid type or no types specified");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "cannot be empty");
+               RETURN_THROWS();
        }
 
        if (types_len != (size_t) argc) {
                /* number of bind variables doesn't match number of elements in type definition string */
-               php_error_docref(NULL, E_WARNING, "Number of elements in type definition string doesn't match number of bind variables");
-               RETURN_FALSE;
+               zend_argument_count_error("The number of elements in the type definition string must match the number of bind variables");
+               RETURN_THROWS();
        }
 
        if (types_len != mysql_stmt_param_count(stmt->stmt)) {
-               php_error_docref(NULL, E_WARNING, "Number of variables doesn't match number of parameters in prepared statement");
-               RETURN_FALSE;
+               zend_argument_count_error("The number of variables must match the number of parameters in the prepared statement");
+               RETURN_THROWS();
        }
 
        RETVAL_BOOL(!mysqli_stmt_bind_param_do_bind(stmt, argc, args, types, getThis() ? 1 : 2));
@@ -557,8 +559,8 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
        MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
 
        if ((uint32_t)argc != mysql_stmt_field_count(stmt->stmt)) {
-               php_error_docref(NULL, E_WARNING, "Number of bind variables doesn't match number of fields in prepared statement");
-               RETURN_FALSE;
+               zend_argument_count_error("Number of bind variables doesn't match number of fields in prepared statement");
+               RETURN_THROWS();
        }
 
        rc = mysqli_stmt_bind_result_do_bind(stmt, args, argc);
@@ -729,14 +731,23 @@ PHP_FUNCTION(mysqli_data_seek)
                RETURN_THROWS();
        }
 
+       if (offset < 0) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+               RETURN_THROWS();
+       }
+
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
 
        if (mysqli_result_is_unbuffered(result)) {
-               php_error_docref(NULL, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
-               RETURN_FALSE;
+               if (getThis()) {
+                       zend_throw_error(NULL, "mysqli_result::data_seek() cannot be used with MYSQLI_USE_RESULT");
+               } else {
+                       zend_throw_error(NULL, "mysqli_data_seek() cannot be used with MYSQLI_USE_RESULT");
+               }
+               RETURN_THROWS();
        }
 
-       if (offset < 0 || (uint64_t)offset >= mysql_num_rows(result)) {
+       if ((uint64_t)offset >= mysql_num_rows(result)) {
                RETURN_FALSE;
        }
 
@@ -1181,11 +1192,16 @@ PHP_FUNCTION(mysqli_fetch_field_direct)
                RETURN_THROWS();
        }
 
+       if (offset < 0) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+               RETURN_THROWS();
+       }
+
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
 
-       if (offset < 0 || offset >= (zend_long) mysql_num_fields(result)) {
-               php_error_docref(NULL, E_WARNING, "Field offset is invalid for resultset");
-               RETURN_FALSE;
+       if (offset >= (zend_long) mysql_num_fields(result)) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be less than the number of fields for this result set");
+               RETURN_THROWS();
        }
 
        if (!(field = mysql_fetch_field_direct(result,offset))) {
@@ -1215,6 +1231,7 @@ PHP_FUNCTION(mysqli_fetch_lengths)
 
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
 
+       // TODO Warning?
        if (!(ret = mysql_fetch_lengths(result))) {
                RETURN_FALSE;
        }
@@ -1260,9 +1277,16 @@ PHP_FUNCTION(mysqli_field_seek)
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_result, mysqli_result_class_entry, &fieldnr) == FAILURE) {
                RETURN_THROWS();
        }
+
+       if (fieldnr < 0) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+               RETURN_THROWS();
+       }
+
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
 
-       if (fieldnr < 0 || (uint32_t)fieldnr >= mysql_num_fields(result)) {
+       if ((uint32_t)fieldnr >= mysql_num_fields(result)) {
+               // TODO ValueError?
                php_error_docref(NULL, E_WARNING, "Invalid field offset");
                RETURN_FALSE;
        }
@@ -1499,13 +1523,14 @@ PHP_FUNCTION(mysqli_kill)
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_link, mysqli_link_class_entry, &processid) == FAILURE) {
                RETURN_THROWS();
        }
-       MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
 
        if (processid <= 0) {
-               php_error_docref(NULL, E_WARNING, "processid should have positive value");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than 0");
+               RETURN_THROWS();
        }
 
+       MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
+
        if (mysql_kill(mysql->mysql, processid)) {
                MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
                RETURN_FALSE;
@@ -1601,8 +1626,8 @@ PHP_FUNCTION(mysqli_num_rows)
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
 
        if (mysqli_result_is_unbuffered_and_not_everything_is_fetched(result)) {
-               php_error_docref(NULL, E_WARNING, "Function cannot be used with MYSQL_USE_RESULT");
-               RETURN_LONG(0);
+               zend_throw_error(NULL, "mysqli_num_rows() cannot be used with MYSQLI_USE_RESULT");
+               RETURN_THROWS();
        }
 
        MYSQLI_RETURN_LONG_INT(mysql_num_rows(result));
@@ -1922,12 +1947,14 @@ PHP_FUNCTION(mysqli_stmt_send_long_data)
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ols", &mysql_stmt, mysqli_stmt_class_entry, &param_nr, &data, &data_len) == FAILURE) {
                RETURN_THROWS();
        }
+
        MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
 
        if (param_nr < 0) {
-               php_error_docref(NULL, E_WARNING, "Invalid parameter number");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
+
        if (mysql_stmt_send_long_data(stmt->stmt, param_nr, data, data_len)) {
                RETURN_FALSE;
        }
@@ -1984,9 +2011,10 @@ PHP_FUNCTION(mysqli_stmt_data_seek)
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_stmt, mysqli_stmt_class_entry, &offset) == FAILURE) {
                RETURN_THROWS();
        }
+
        if (offset < 0) {
-               php_error_docref(NULL, E_WARNING, "Offset must be positive");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
@@ -2216,7 +2244,7 @@ PHP_FUNCTION(mysqli_stmt_attr_set)
        zval    *mysql_stmt;
        zend_long       mode_in;
 #if MYSQL_VERSION_ID >= 50107
-       my_bool mode_b;
+       my_bool mode_b;
 #endif
        unsigned long   mode;
        zend_long       attr;
@@ -2225,25 +2253,54 @@ PHP_FUNCTION(mysqli_stmt_attr_set)
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oll", &mysql_stmt, mysqli_stmt_class_entry, &attr, &mode_in) == FAILURE) {
                RETURN_THROWS();
        }
-       MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
 
-       if (mode_in < 0) {
-               php_error_docref(NULL, E_WARNING, "Mode should be non-negative, " ZEND_LONG_FMT " passed", mode_in);
-               RETURN_FALSE;
-       }
+       MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
 
        switch (attr) {
 #if MYSQL_VERSION_ID >= 50107
        case STMT_ATTR_UPDATE_MAX_LENGTH:
+               if (mode_in != 0 && mode_in != 1) {
+                       zend_argument_value_error(ERROR_ARG_POS(3), "must be 0 or 1 for attribute MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH");
+                       RETURN_THROWS();
+               }
                mode_b = (my_bool) mode_in;
                mode_p = &mode_b;
                break;
 #endif
-       default:
+       case STMT_ATTR_CURSOR_TYPE:
+               switch (mode_in) {
+                       case CURSOR_TYPE_NO_CURSOR:
+                       case CURSOR_TYPE_READ_ONLY:
+                       case CURSOR_TYPE_FOR_UPDATE:
+                       case CURSOR_TYPE_SCROLLABLE:
+                               break;
+                       default:
+                               zend_argument_value_error(ERROR_ARG_POS(3), "must be one of MYSQLI_CURSOR_TYPE_NO_CURSOR, "
+                                       "MYSQLI_CURSOR_TYPE_READ_ONLY, MYSQLI_CURSOR_TYPE_FOR_UPDATE, or MYSQLI_CURSOR_TYPE_SCROLLABLE "
+                                       "for attribute MYSQLI_STMT_ATTR_CURSOR_TYPE");
+                               RETURN_THROWS();
+               }
                mode = mode_in;
                mode_p = &mode;
                break;
+       case STMT_ATTR_PREFETCH_ROWS:
+               if (mode_in < 1) {
+                       zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than 0 for attribute MYSQLI_STMT_ATTR_PREFETCH_ROWS");
+                       RETURN_THROWS();
+               }
+               mode = mode_in;
+               mode_p = &mode;
+               break;
+       default:
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be one of "
+#if MYSQL_VERSION_ID >= 50107
+                       "MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, "
+#endif
+                       "MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE");
+               RETURN_THROWS();
        }
+
+// TODO Can unify this?
 #ifndef MYSQLI_USE_MYSQLND
        if (mysql_stmt_attr_set(stmt->stmt, attr, mode_p)) {
 #else
@@ -2267,11 +2324,20 @@ PHP_FUNCTION(mysqli_stmt_attr_get)
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Ol", &mysql_stmt, mysqli_stmt_class_entry, &attr) == FAILURE) {
                RETURN_THROWS();
        }
+
        MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
 
        if ((rc = mysql_stmt_attr_get(stmt->stmt, attr, &value))) {
-               RETURN_FALSE;
-       }
+               /* Success corresponds to 0 return value and a non-zero value
+                * should only happen if the attr/option is unknown */
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be one of "
+#if MYSQL_VERSION_ID >= 50107
+                       "MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, "
+#endif
+                       "MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE");
+               RETURN_THROWS();
+    }
+
 
 #if MYSQL_VERSION_ID >= 50107
        if (attr == STMT_ATTR_UPDATE_MAX_LENGTH)
index 7d7c69e94391951328f9548bfc960a5f1cb8983e..15daa38426a18070c1554e49739a3a7099a26969 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: a8626c7c42e4d117b08df7f42a7523f60f357b82 */
+ * Stub hash: beb821b6e0b26f798d88f7b726a39084d856251f */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1, MAY_BE_LONG|MAY_BE_STRING)
        ZEND_ARG_OBJ_INFO(0, mysql_link, mysqli, 0)
@@ -233,7 +233,7 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_mysqli_query, 0, 2, mysqli_result, MAY_BE_BOOL)
        ZEND_ARG_OBJ_INFO(0, mysqli_link, mysqli, 0)
        ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0)
-       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, resultmode, IS_LONG, 0, "MYSQLI_STORE_RESULT")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_mode, IS_LONG, 0, "MYSQLI_STORE_RESULT")
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_real_connect, 0, 1, _IS_BOOL, 0)
@@ -285,7 +285,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_stmt_affected_rows, 0, 1,
        ZEND_ARG_OBJ_INFO(0, mysql_stmt, mysqli_stmt, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_stmt_attr_get, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_stmt_attr_get, 0, 2, IS_LONG, 0)
        ZEND_ARG_OBJ_INFO(0, mysql_stmt, mysqli_stmt, 0)
        ZEND_ARG_TYPE_INFO(0, attr, IS_LONG, 0)
 ZEND_END_ARG_INFO()
@@ -309,7 +309,7 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_mysqli_stmt_close arginfo_mysqli_stmt_execute
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_stmt_data_seek, 0, 2, _IS_BOOL, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_stmt_data_seek, 0, 2, IS_VOID, 0)
        ZEND_ARG_OBJ_INFO(0, mysql_stmt, mysqli_stmt, 0)
        ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
 ZEND_END_ARG_INFO()
@@ -502,7 +502,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_query, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, query, IS_STRING, 0)
-       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, resultmode, IS_LONG, 0, "MYSQLI_STORE_RESULT")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_mode, IS_LONG, 0, "MYSQLI_STORE_RESULT")
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_real_connect, 0, 0, 0)
@@ -576,7 +576,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_result___construct, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, mysqli_link, IS_OBJECT, 0)
-       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, resmode, IS_LONG, 0, "MYSQLI_STORE_RESULT")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_mode, IS_LONG, 0, "MYSQLI_STORE_RESULT")
 ZEND_END_ARG_INFO()
 
 #define arginfo_class_mysqli_result_close arginfo_class_mysqli_character_set_name
index 9b675bb5263263036643b264a68e0a1575a42e6e..394afc7ccc9932ed5aa0c12b604e906495bcbba8 100644 (file)
@@ -28,6 +28,7 @@
 #include "zend_smart_str.h"
 #include "php_mysqli_structs.h"
 #include "mysqli_priv.h"
+#define ERROR_ARG_POS(arg_num) (getThis() ? (arg_num-1) : (arg_num))
 
 #define SAFE_STR(a) ((a)?a:"")
 
@@ -435,9 +436,9 @@ PHP_FUNCTION(mysqli_fetch_all)
        MYSQLI_FETCH_RESOURCE(result, MYSQL_RES *, mysql_result, "mysqli_result", MYSQLI_STATUS_VALID);
 
        if (!mode || (mode & ~MYSQLND_FETCH_BOTH)) {
-               php_error_docref(NULL, E_WARNING, "Mode can be only MYSQLI_FETCH_NUM, "
-                                "MYSQLI_FETCH_ASSOC or MYSQLI_FETCH_BOTH");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be one of MYSQLI_FETCH_NUM, "
+                                "MYSQLI_FETCH_ASSOC, or MYSQLI_FETCH_BOTH");
+               RETURN_THROWS();
        }
 
        mysqlnd_fetch_all(result, mode, return_value);
@@ -631,16 +632,18 @@ PHP_FUNCTION(mysqli_query)
        }
 
        if (!query_len) {
-               php_error_docref(NULL, E_WARNING, "Empty query");
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "cannot be empty");
+               RETURN_THROWS();
        }
-#ifdef MYSQLI_USE_MYSQLND
-       if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT && (resultmode & ~(MYSQLI_ASYNC | MYSQLI_STORE_RESULT_COPY_DATA)) != MYSQLI_STORE_RESULT) {
-#else
-       if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT && (resultmode & ~MYSQLI_ASYNC) != MYSQLI_STORE_RESULT) {
-#endif
-               php_error_docref(NULL, E_WARNING, "Invalid value for resultmode");
-               RETURN_FALSE;
+       if ((resultmode & ~MYSQLI_ASYNC) != MYSQLI_USE_RESULT &&
+               MYSQLI_STORE_RESULT != (resultmode & ~(MYSQLI_ASYNC | MYSQLI_STORE_RESULT_COPY_DATA))
+       ) {
+               zend_argument_value_error(ERROR_ARG_POS(3), "must be either MYSQLI_USE_RESULT, or MYSQLI_STORE_RESULT"
+                       #ifdef MYSQLI_USE_MYSQLND
+                               " with MYSQLI_ASYNC as an optional bitmask flag"
+                       #endif
+               );
+               RETURN_THROWS();
        }
 
        MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
@@ -722,7 +725,8 @@ static int mysqlnd_zval_array_to_mysqlnd_array(zval *in_array, MYSQLND ***out_ar
                i++;
                if (Z_TYPE_P(elem) != IS_OBJECT ||
                        !instanceof_function(Z_OBJCE_P(elem), mysqli_link_class_entry)) {
-                       php_error_docref(NULL, E_WARNING, "Parameter %d not a mysqli object", i);
+                       zend_argument_type_error(i, "must be an instance of mysqli, %s given", zend_zval_type_name(elem));
+                       return FAILURE;
                } else {
                        MY_MYSQL *mysql;
                        MYSQLI_RESOURCE *my_res;
@@ -831,11 +835,16 @@ PHP_FUNCTION(mysqli_poll)
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "a!a!al|l", &r_array, &e_array, &dont_poll_array, &sec, &usec) == FAILURE) {
                RETURN_THROWS();
        }
-       if (sec < 0 || usec < 0) {
-               php_error_docref(NULL, E_WARNING, "Negative values passed for sec and/or usec");
-               RETURN_FALSE;
+       if (sec < 0) {
+               zend_argument_value_error(4, "must be greater than or equal to 0");
+               RETURN_THROWS();
+       }
+       if (usec < 0) {
+               zend_argument_value_error(5, "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
+       // TODO Error promotion
        if (!r_array && !e_array) {
                php_error_docref(NULL, E_WARNING, "No stream arrays were passed");
                RETURN_FALSE;
@@ -1152,22 +1161,18 @@ PHP_FUNCTION(mysqli_begin_transaction)
        zend_long               flags = TRANS_START_NO_OPT;
        char *          name = NULL;
        size_t                  name_len = -1;
-       zend_bool       err = FALSE;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ls!", &mysql_link, mysqli_link_class_entry, &flags, &name, &name_len) == FAILURE) {
                RETURN_THROWS();
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
        if (flags < 0) {
-               php_error_docref(NULL, E_WARNING, "Invalid value for parameter flags (" ZEND_LONG_FMT ")", flags);
-               err = TRUE;
+               zend_argument_value_error(ERROR_ARG_POS(2), "must be one of the MYSQLI_TRANS_* constants");
+               RETURN_THROWS();
        }
        if (!name_len) {
-               php_error_docref(NULL, E_WARNING, "Savepoint name cannot be empty");
-               err = TRUE;
-       }
-       if (TRUE == err) {
-               RETURN_FALSE;
+               zend_argument_value_error(ERROR_ARG_POS(3), "cannot be empty");
+               RETURN_THROWS();
        }
 
 #ifndef MYSQLI_USE_MYSQLND
@@ -1203,15 +1208,15 @@ PHP_FUNCTION(mysqli_savepoint)
        MY_MYSQL        *mysql;
        zval            *mysql_link;
        char *          name = NULL;
-       size_t                  name_len = -1;
+       size_t                  name_len;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &mysql_link, mysqli_link_class_entry, &name, &name_len) == FAILURE) {
                RETURN_THROWS();
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-       if (!name || !name_len) {
-               php_error_docref(NULL, E_WARNING, "Savepoint name cannot be empty");
-               RETURN_FALSE;
+       if (name_len == 0) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "cannot be empty");
+               RETURN_THROWS();
        }
 
 #ifndef MYSQLI_USE_MYSQLND
@@ -1231,15 +1236,15 @@ PHP_FUNCTION(mysqli_release_savepoint)
        MY_MYSQL        *mysql;
        zval            *mysql_link;
        char *          name = NULL;
-       size_t                  name_len = -1;
+       size_t                  name_len;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &mysql_link, mysqli_link_class_entry, &name, &name_len) == FAILURE) {
                RETURN_THROWS();
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
-       if (!name || !name_len) {
-               php_error_docref(NULL, E_WARNING, "Savepoint name cannot be empty");
-               RETURN_FALSE;
+       if (name_len == 0) {
+               zend_argument_value_error(ERROR_ARG_POS(2), "cannot be empty");
+               RETURN_THROWS();
        }
 #ifndef MYSQLI_USE_MYSQLND
        if (mysqli_savepoint_libmysql(mysql->mysql, name, TRUE)) {
index 86626c0279f79d5287a683b8c0c4751fde7e5b2e..817f7eecfe557cfab9476e2af1c8bf836cbf48a5 100644 (file)
@@ -15,27 +15,31 @@ require_once("connect.inc");
 
     var_dump($link->real_query("SELECT 1"));
     $res = $link->use_result();
-    var_dump(mysqli_num_rows($res));
+    try {
+        var_dump(mysqli_num_rows($res));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     var_dump($res->fetch_assoc());
-    var_dump(mysqli_num_rows($res));
+    try {
+        var_dump(mysqli_num_rows($res));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     var_dump($res->fetch_assoc());
     var_dump(mysqli_num_rows($res));
 
     $link->close();
     echo "done\n";
 ?>
---EXPECTF--
+--EXPECT--
 bool(true)
-
-Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
-int(0)
+mysqli_num_rows() cannot be used with MYSQLI_USE_RESULT
 array(1) {
   [1]=>
   string(1) "1"
 }
-
-Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
-int(0)
+mysqli_num_rows() cannot be used with MYSQLI_USE_RESULT
 NULL
 int(1)
 done
diff --git a/ext/mysqli/tests/bug74595.phpt b/ext/mysqli/tests/bug74595.phpt
deleted file mode 100644 (file)
index 9d017ea..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
---TEST--
-Bug #74595 (ReflectionMethod::getParameters returns incorrect number of parameters)
---SKIPIF--
-<?php
-require_once('skipif.inc');
-?>
---FILE--
-<?php
-$class = new ReflectionClass('mysqli');
-$method = $class->getMethod('query');
-var_dump($method->getParameters());
-?>
---EXPECTF--
-array(2) {
-  [0]=>
-  object(ReflectionParameter)#%d (1) {
-    ["name"]=>
-    string(5) "query"
-  }
-  [1]=>
-  object(ReflectionParameter)#%d (1) {
-    ["name"]=>
-    string(10) "resultmode"
-  }
-}
index 43bb3c4153f83ceded5daa35e88d04c525bc14e0..6bf393a2de6654599adc1838b9d49e0fe508dbaf 100644 (file)
@@ -8,7 +8,7 @@
 
     $driver    = new mysqli_driver;
 
-    $host      = getenv("MYSQL_TEST_HOST")     ?: "localhost";
+    $host      = getenv("MYSQL_TEST_HOST")     ?: "127.0.0.1";
     $port      = getenv("MYSQL_TEST_PORT")     ?: 3306;
     $user      = getenv("MYSQL_TEST_USER")     ?: "root";
     $passwd    = getenv("MYSQL_TEST_PASSWD")   ?: "";
index bed9b1bf6132156bb48606ae9581eb61bee459fb..7a9107b7e69170fa96bfa3081c9bc3e2aa89f287 100644 (file)
@@ -76,8 +76,11 @@ if (!have_innodb($link))
         }
     }
 
-    if (!mysqli_begin_transaction($link, -1)) {
-            printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+    try {
+        mysqli_begin_transaction($link, -1);
+        printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
     }
 
     if (mysqli_get_server_version($link) >= 50605) {
@@ -96,9 +99,7 @@ if (!have_innodb($link))
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
+--EXPECT--
 NULL
-
-Warning: mysqli_begin_transaction(): Invalid value for parameter flags (-1) in %s on line %d
-[019] [%d]%A
+mysqli_begin_transaction(): Argument #2 ($flags) must be one of the MYSQLI_TRANS_* constants
 done!
index 53c8b8354d5b216064cf2229a70efe187408ff65..2b477af3fd4b12a7b6ed698b24cd0910595c0d45 100644 (file)
@@ -31,16 +31,22 @@ require_once('skipifconnectfailure.inc');
     if (false !== ($tmp = mysqli_data_seek($res, 4)))
         printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
 
-    if (false !== ($tmp = mysqli_data_seek($res, -1)))
-        printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_data_seek($res, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     mysqli_free_result($res);
 
     if (!$res = mysqli_query($link, 'SELECT * FROM test ORDER BY id', MYSQLI_USE_RESULT))
         printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
 
-    if (false !== ($tmp = mysqli_data_seek($res, 3)))
-        printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        var_dump(mysqli_data_seek($res, 3));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     mysqli_free_result($res);
 
@@ -58,7 +64,8 @@ require_once('skipifconnectfailure.inc');
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
-Warning: mysqli_data_seek(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
+--EXPECT--
+mysqli_data_seek(): Argument #2 ($offset) must be greater than or equal to 0
+mysqli_data_seek() cannot be used with MYSQLI_USE_RESULT
 mysqli_result object is already closed
 done!
index 0d1ee8b79f6e57e84b9a074d486709c32ba69538..ccbf86542ac5960e68057a80b9b7aa7b3043249c 100644 (file)
@@ -43,16 +43,22 @@ require_once('skipifconnectfailure.inc');
     if (false !== ($tmp = $res->data_seek(4)))
         printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
 
-    if (false !== ($tmp = $res->data_seek(-1)))
-        printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        $res->data_seek(-1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     $res->free_result();
 
     if (!$res = $mysqli->query('SELECT * FROM test ORDER BY id', MYSQLI_USE_RESULT))
         printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
 
-    if (false !== ($tmp = $res->data_seek(3)))
-        printf("[014] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        var_dump($res->data_seek(3));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     $res->free_result();
 
@@ -69,9 +75,9 @@ require_once('skipifconnectfailure.inc');
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
+--EXPECT--
 mysqli_result object is already closed
-
-Warning: mysqli_result::data_seek(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
+mysqli_result::data_seek(): Argument #1 ($offset) must be greater than or equal to 0
+mysqli_result::data_seek() cannot be used with MYSQLI_USE_RESULT
 mysqli_result object is already closed
 done!
index 76c6b971f41a96a82a43a902b7d7b4c1594421e8..ab48821498e0d4d2cb21ac81981318dbf3a9f383 100644 (file)
@@ -71,12 +71,12 @@ if (!function_exists('mysqli_fetch_all'))
             exit(1);
     }
 
-    do {
-            $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.
-
-    mysqli_fetch_all($res, $illegal_mode);
+    // Illegal mode
+    try {
+        mysqli_fetch_all($res, -10);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     mysqli_free_result($res);
 
     function func_mysqli_fetch_all($link, $engine, $sql_type, $sql_value, $php_value, $offset, $regexp_comparison = NULL) {
@@ -315,7 +315,7 @@ if (!function_exists('mysqli_fetch_all'))
 <?php
        // require_once("clean_table.inc");
 ?>
---EXPECTF--
+--EXPECT--
 [005]
 array(2) {
   [0]=>
@@ -443,7 +443,6 @@ array(1) {
     string(1) "1"
   }
 }
-
-Warning: mysqli_fetch_all(): Mode can be only MYSQLI_FETCH_NUM, MYSQLI_FETCH_ASSOC or MYSQLI_FETCH_BOTH in %s on line %d
+mysqli_fetch_all(): Argument #2 ($mode) must be one of MYSQLI_FETCH_NUM, MYSQLI_FETCH_ASSOC, or MYSQLI_FETCH_BOTH
 mysqli_result object is already closed
 done!
index 992a61a348bc887f637285f7d72a8078fd6e5885..2b34670756583056d9f3fd19821e8ae8efde33cb 100644 (file)
@@ -81,14 +81,14 @@ if (!function_exists('mysqli_fetch_all'))
         exit(1);
     }
 
-    do {
-        $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_all($illegal_mode);
-    if (false !== $tmp)
-        printf("[019] Expecting boolean/false although, got %s/%s. [%d] %s\n",
-            gettype($tmp), $tmp, $mysqli->errno, $mysqli->error);
+    try {
+        $tmp = $res->fetch_all(-10);
+        if (false !== $tmp)
+            printf("[019] Expecting boolean/false although, got %s/%s. [%d] %s\n",
+                gettype($tmp), $tmp, $mysqli->errno, $mysqli->error);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     $res->free_result();
 
@@ -436,7 +436,6 @@ array(1) {
     string(1) "1"
   }
 }
-
-Warning: mysqli_result::fetch_all(): Mode can be only MYSQLI_FETCH_NUM, MYSQLI_FETCH_ASSOC or MYSQLI_FETCH_BOTH in %s on line %d
+mysqli_result::fetch_all(): Argument #1 ($result_type) must be one of MYSQLI_FETCH_NUM, MYSQLI_FETCH_ASSOC, or MYSQLI_FETCH_BOTH
 mysqli_result object is already closed
 done!
index 0afe6e4626af7c8bb5af8b7c4cfda944968fb860..8b57cca094c811b2df241f955cf2a2fee58a4431 100644 (file)
@@ -16,9 +16,18 @@ require_once('skipifconnectfailure.inc');
         printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
     }
 
-    var_dump(mysqli_fetch_field_direct($res, -1));
+    try {
+        var_dump(mysqli_fetch_field_direct($res, -1));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     var_dump(mysqli_fetch_field_direct($res, 0));
-    var_dump(mysqli_fetch_field_direct($res, 2));
+
+    try {
+        var_dump(mysqli_fetch_field_direct($res, 2));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     mysqli_free_result($res);
 
@@ -36,8 +45,7 @@ require_once('skipifconnectfailure.inc');
        require_once("clean_table.inc");
 ?>
 --EXPECTF--
-Warning: mysqli_fetch_field_direct(): Field offset is invalid for resultset in %s on line %d
-bool(false)
+mysqli_fetch_field_direct(): Argument #2 ($offset) must be greater than or equal to 0
 object(stdClass)#%d (13) {
   ["name"]=>
   string(2) "ID"
@@ -66,8 +74,6 @@ object(stdClass)#%d (13) {
   ["decimals"]=>
   int(%d)
 }
-
-Warning: mysqli_fetch_field_direct(): Field offset is invalid for resultset in %s on line %d
-bool(false)
+mysqli_fetch_field_direct(): Argument #2 ($offset) must be less than the number of fields for this result set
 mysqli_result object is already closed
 done!
index 33806f1c553f04e0d64a227dc33c763a123069c6..5dedefcdab1b984bdc80dc981c841edca21d8f80 100644 (file)
@@ -27,9 +27,19 @@ require_once('skipifconnectfailure.inc');
         printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
     }
 
-    var_dump($res->fetch_field_direct(-1));
+    try {
+        var_dump($res->fetch_field_direct(-1));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+
     var_dump($res->fetch_field_direct(0));
-    var_dump($res->fetch_field_direct(2));
+
+    try {
+        var_dump($res->fetch_field_direct(2));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     $res->free_result();
 
@@ -48,9 +58,7 @@ require_once('skipifconnectfailure.inc');
 ?>
 --EXPECTF--
 mysqli object is not fully initialized
-
-Warning: mysqli_result::fetch_field_direct(): Field offset is invalid for resultset in %s on line %d
-bool(false)
+mysqli_result::fetch_field_direct(): Argument #1 ($field_nr) must be greater than or equal to 0
 object(stdClass)#%d (13) {
   ["name"]=>
   string(2) "ID"
@@ -79,8 +87,6 @@ object(stdClass)#%d (13) {
   ["decimals"]=>
   int(%d)
 }
-
-Warning: mysqli_result::fetch_field_direct(): Field offset is invalid for resultset in %s on line %d
-bool(false)
+mysqli_result::fetch_field_direct(): Argument #1 ($field_nr) must be less than the number of fields for this result set
 mysqli_result object is already closed
 done!
index 9eb9f0315b071a2cb131f64c404caa89b448c8e7..bcc1e29526c54568c31d7fc37c89f26b1fe215c9 100644 (file)
@@ -69,7 +69,11 @@ require_once('skipifconnectfailure.inc');
         printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
     }
 
-    var_dump(mysqli_field_seek($res, -1));
+    try {
+        var_dump(mysqli_field_seek($res, -1));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     var_dump(mysqli_fetch_field($res));
     var_dump(mysqli_field_seek($res, 0));
     var_dump(mysqli_fetch_field($res));
@@ -115,8 +119,7 @@ require_once('skipifconnectfailure.inc');
        require_once("clean_table.inc");
 ?>
 --EXPECTF--
-Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
-bool(false)
+mysqli_field_seek(): Argument #2 ($field_nr) must be greater than or equal to 0
 object(stdClass)#%d (13) {
   ["name"]=>
   string(2) "id"
index bf169003aa7e045088699ba69556d59e00fe3e9c..e8c344ec956ff156bdfcc3f29812d03b797a13d1 100644 (file)
@@ -24,7 +24,11 @@ require_once('skipifconnectfailure.inc');
     var_dump(mysqli_field_seek($res, 2));
     var_dump(mysqli_field_tell($res));
 
-    var_dump(mysqli_field_seek($res, -1));
+    try {
+        var_dump(mysqli_field_seek($res, -1));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     var_dump(mysqli_field_tell($res));
 
     var_dump(mysqli_field_seek($res, 0));
@@ -85,9 +89,7 @@ int(1)
 Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
 bool(false)
 int(1)
-
-Warning: mysqli_field_seek(): Invalid field offset in %s on line %d
-bool(false)
+mysqli_field_seek(): Argument #2 ($field_nr) must be greater than or equal to 0
 int(1)
 bool(true)
 int(0)
index 943e213a81a36dcf8598a7bd6a037801d2448681..e4be618fc7fa6162e545d0bad0bc570c67304063 100644 (file)
@@ -13,8 +13,11 @@ require_once('skipifconnectfailure.inc');
     require('table.inc');
 
     // Zend will cast the NULL to 0
-    if (!is_bool($tmp = mysqli_kill($link, null)))
-        printf("[003] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_kill($link, null);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (!$thread_id = mysqli_thread_id($link))
         printf("[004] Cannot determine thread id, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
@@ -46,7 +49,11 @@ require_once('skipifconnectfailure.inc');
     if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
         printf("[010] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
 
-    mysqli_kill($link, -1);
+    try {
+        mysqli_kill($link, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     if ((!$res = mysqli_query($link, "SELECT id FROM test LIMIT 1")) ||
         (!$tmp = mysqli_fetch_assoc($res))) {
         printf("[011] Connection should not be gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
@@ -58,7 +65,12 @@ require_once('skipifconnectfailure.inc');
     if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
         printf("[012] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
 
-    mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);      mysqli_kill($link, -1);
+    mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);
+    try {
+        mysqli_kill($link, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     mysqli_close($link);
 
@@ -69,7 +81,7 @@ require_once('skipifconnectfailure.inc');
        require_once("clean_table.inc");
 ?>
 --EXPECTF--
-Warning: mysqli_kill(): processid should have positive value in %s on line %d
+mysqli_kill(): Argument #2 ($connection_id) must be greater than 0
 string(%d) "%s"
 bool(false)
 object(mysqli)#%d (%d) {
@@ -120,12 +132,10 @@ object(mysqli)#%d (%d) {
   ["warning_count"]=>
   int(0)
 }
-
-Warning: mysqli_kill(): processid should have positive value in %s on line %d
+mysqli_kill(): Argument #2 ($connection_id) must be greater than 0
 array(1) {
   ["id"]=>
   string(1) "1"
 }
-
-Warning: mysqli_kill(): processid should have positive value in %s on line %d
+mysqli_kill(): Argument #2 ($connection_id) must be greater than 0
 done!
index 3266f37dce1727369774a1599d1ce83cfee67cdd..4d09c256823a767b3f71618ca5d6e9ac95fa0ea1 100644 (file)
@@ -56,8 +56,11 @@ require_once('skipifconnectfailure.inc');
     if ($res = mysqli_query($link, 'SELECT id FROM test', MYSQLI_USE_RESULT)) {
 
         $row = mysqli_fetch_row($res);
-        if (0 !== ($tmp = mysqli_num_rows($res)))
-            printf("[031] Expecting int/0, got %s/%d\n", gettype($tmp), $tmp);
+        try {
+            var_dump(mysqli_num_rows($res));
+        } catch (\Error $e) {
+            echo $e->getMessage() . \PHP_EOL;
+        }
 
         mysqli_free_result($res);
     } else {
@@ -71,12 +74,11 @@ require_once('skipifconnectfailure.inc');
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
+--EXPECT--
 mysqli_result object is already closed
 mysqli_result object is already closed
 mysqli_result object is already closed
 mysqli_result object is already closed
 run_tests.php don't fool me with your 'ungreedy' expression '.+?'!
-
-Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
+mysqli_num_rows() cannot be used with MYSQLI_USE_RESULT
 done!
index 97b1a7e61ad776519000b58d0d441148b95e4fdb..cc3cc36b2f8fbd060ba364374d7d0d824f97ea8f 100644 (file)
@@ -30,12 +30,16 @@ if (!$IS_MYSQLND)
         printf("[009] Expecting int/0 got %s/%s\n", gettype($tmp), var_export($tmp, true));
 
     $read = $error = $reject = array($link);
-    if (false !== ($tmp = (mysqli_poll($read, $error, $reject, -1, 1))))
-        printf("[010] Expecting false got %s/%s\n", gettype($tmp), var_export($tmp, true));
-
-    $read = $error = $reject = array($link);
-    if (false !== ($tmp = (mysqli_poll($read, $error, $reject, 0, -1))))
-        printf("[011] Expecting false got %s/%s\n", gettype($tmp), var_export($tmp, true));
+    try {
+        mysqli_poll($read, $error, $reject, -1, 1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+    try {
+        mysqli_poll($read, $error, $reject, 0, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     function poll_async($offset, $link, $links, $errors, $reject, $exp_ready, $use_oo_syntax) {
 
@@ -111,9 +115,8 @@ if (!$IS_MYSQLND)
     print "done!";
 ?>
 --EXPECTF--
-Warning: mysqli_poll(): Negative values passed for sec and/or usec in %s on line %d
-
-Warning: mysqli_poll(): Negative values passed for sec and/or usec in %s on line %d
+mysqli_poll(): Argument #4 ($sec) must be greater than or equal to 0
+mysqli_poll(): Argument #5 ($usec) must be greater than or equal to 0
 [012 + 6] Rejecting thread %d: 0/
 [013 + 6] Rejecting thread %d: 0/
 [014 + 6] Rejecting thread %d: 0/
index ba159cf9852ed9cb9c285e207859e9b78cb0fbd3..daac374cf797609d517f2d2f8517250943d507e6 100644 (file)
@@ -12,8 +12,11 @@ require_once('skipifconnectfailure.inc');
 
     require('table.inc');
 
-    if (false !== ($tmp = @mysqli_query($link, '')))
-        printf("[002a] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_query($link, '');
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (false !== ($tmp = mysqli_query($link, 'THIS IS NOT SQL')))
         printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
@@ -82,11 +85,11 @@ require_once('skipifconnectfailure.inc');
         printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
     mysqli_free_result($res);
 
-    if (false !== ($res = @mysqli_query($link, "SELECT id FROM test ORDER BY id", 1234)))
-        printf("[013] Invalid mode should return false got %s/%s, [%d] %s\n",
-            gettype($res), (is_object($res)) ? 'object' : $res,
-            mysqli_errno($link), mysqli_error($link));
-
+    try {
+        mysqli_query($link, "SELECT id FROM test ORDER BY id", 1234);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     mysqli_close($link);
 
@@ -113,6 +116,7 @@ if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
 mysqli_close($link);
 ?>
 --EXPECT--
+mysqli_query(): Argument #2 ($query) cannot be empty
 array(1) {
   ["valid"]=>
   string(30) "this is sql but with semicolon"
@@ -122,5 +126,6 @@ array(1) {
   string(1) "a"
 }
 string(1) "a"
+mysqli_query(): Argument #3 ($result_mode) must be either MYSQLI_USE_RESULT, or MYSQLI_STORE_RESULT with MYSQLI_ASYNC as an optional bitmask flag
 mysqli object is already closed
 done!
index 92f85c8b7576c86b5d45ba92e6d3f0f22edf4f05..fa46366e7cac8b471b5fc9c438d8e85aa36c3ecd 100644 (file)
@@ -23,8 +23,11 @@ if (!have_innodb($link))
         printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
             $host, $user, $db, $port, $socket);
 
-    if (false !== ($tmp = mysqli_release_savepoint($link, '')))
-        printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_release_savepoint($link, '');
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
         printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
@@ -61,8 +64,8 @@ if (!have_innodb($link))
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
-Warning: mysqli_release_savepoint(): Savepoint name cannot be empty in %s on line %d
+--EXPECT--
+mysqli_release_savepoint(): Argument #2 ($name) cannot be empty
 array(1) {
   ["id"]=>
   string(1) "1"
index 17baea0f66f9561620a7694df997acdcfee98b4c..6f5733513ca3b9c8cd3a090187a7d7e3de592fe2 100644 (file)
@@ -37,7 +37,11 @@ require_once('skipifconnectfailure.inc');
 
     mysqli_multi_query($link, "BAR; FOO;");
     mysqli_query($link, "FOO");
-    mysqli_kill($link, -1);
+    try {
+        mysqli_kill($link, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     // mysqli_ping() cannot be tested, because one would need to cause an error inside the C function to test it
     mysqli_prepare($link, "FOO");
@@ -53,7 +57,11 @@ require_once('skipifconnectfailure.inc');
 
     mysqli_multi_query($link, "BAR; FOO;");
     mysqli_query($link, "FOO");
-    mysqli_kill($link, -1);
+    try {
+        mysqli_kill($link, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     mysqli_prepare($link, "FOO");
     mysqli_real_query($link, "FOO");
     mysqli_select_db($link, "Oh lord, let this be an unknown database name");
@@ -280,14 +288,12 @@ require_once('skipifconnectfailure.inc');
 Warning: mysqli_multi_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'BAR; FOO' at line 1 in %s on line %d
 
 Warning: mysqli_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
-
-Warning: mysqli_kill(): processid should have positive value in %s on line %d
+mysqli_kill(): Argument #2 ($connection_id) must be greater than 0
 
 Warning: mysqli_prepare(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
 
 Warning: mysqli_real_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
-
-Warning: mysqli_kill(): processid should have positive value in %s on line %d
+mysqli_kill(): Argument #2 ($connection_id) must be greater than 0
 
 Warning: mysqli_stmt_prepare(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
 [013] Access denied for user '%s'@'%s' (using password: YES)
index 9f902920dbf44a4815cae3a01f835b33ee2acef8..374fccfa61e81f7754c3b3da4a1a4aa7ebf5ae21 100644 (file)
@@ -12,19 +12,19 @@ require_once('skipifconnectfailure.inc');
     require('table.inc');
 
     $valid = array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT);
-    do {
-        $mode = mt_rand(-1000, 1000);
-    } while (in_array($mode, $valid));
-
-    if (!is_object($res = new mysqli_result($link, $mode)))
-        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
-
-    print "done!";
+    $invalidModes = [-1, 152];
+    foreach ($invalidModes as $mode) {
+        try {
+            new mysqli_result($link, $mode);
+        } catch (\ValueError $e) {
+            echo $e->getMessage() . \PHP_EOL;
+        }
+    }
 ?>
 --CLEAN--
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
-Warning: mysqli_result::__construct(): Invalid value for resultmode in %s on line %d
-done!
+--EXPECT--
+mysqli_result::__construct(): Argument #2 ($result_mode) must be either MYSQLI_STORE_RESULT or MYSQLI_USE_RESULT
+mysqli_result::__construct(): Argument #2 ($result_mode) must be either MYSQLI_STORE_RESULT or MYSQLI_USE_RESULT
index 524d21e5c3eb4290f685a0752b8d761c71c461b5..10016256671d3a16836a1db5b9467ad676edb152 100644 (file)
@@ -21,8 +21,11 @@ if (!have_innodb($link))
         printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
             $host, $user, $db, $port, $socket);
 
-    if (false !== ($tmp = mysqli_savepoint($link, '')))
-        printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_savepoint($link, '');
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
         printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
@@ -50,6 +53,6 @@ if (!have_innodb($link))
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
-Warning: mysqli_savepoint(): Savepoint name cannot be empty in %s on line %d
+--EXPECT--
+mysqli_savepoint(): Argument #2 ($name) cannot be empty
 done!
index 0844a6c8acc7c2cbf3a9685f2e093884d1baae42..6179155e777b198c099277451c827d010ba4876c 100644 (file)
@@ -19,20 +19,17 @@ require_once('skipifconnectfailure.inc');
     if ($IS_MYSQLND && mysqli_get_client_version() > 50007)
         $valid_attr["prefetch_rows"] = MYSQLI_STMT_ATTR_PREFETCH_ROWS;
 
-    do {
-        $invalid_attr = mt_rand(0, 10000);
-    } while (in_array($invalid_attr, $valid_attr));
-
     $stmt = mysqli_stmt_init($link);
     mysqli_stmt_prepare($stmt, 'SELECT * FROM test');
 
     try {
-        mysqli_stmt_attr_get($stmt, $invalid_attr);
-    } catch (Error $exception) {
-        echo $exception->getMessage() . "\n";
+        mysqli_stmt_attr_get($stmt, -100);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
     }
 
     foreach ($valid_attr as $k => $attr) {
+        /* This can't happen anymore as it only returns int */
         if (false === ($tmp = mysqli_stmt_attr_get($stmt, $attr))) {
             printf("[006] Expecting any type, but not boolean/false, got %s/%s for attribute %s/%s\n",
                 gettype($tmp), $tmp, $k, $attr);
@@ -44,7 +41,7 @@ require_once('skipifconnectfailure.inc');
     foreach ($valid_attr as $k => $attr) {
         try {
             mysqli_stmt_attr_get($stmt, $attr);
-        } catch (Error $exception) {
+        } catch (Throwable $exception) {
             echo $exception->getMessage() . "\n";
         }
     }
@@ -57,6 +54,7 @@ require_once('skipifconnectfailure.inc');
        require_once("clean_table.inc");
 ?>
 --EXPECT--
+mysqli_stmt_attr_get(): Argument #2 ($attr) must be one of MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE
 mysqli_stmt object is already closed
 mysqli_stmt object is already closed
 mysqli_stmt object is already closed
index 4fad53cba2fbe66cd578ab8fb8d2d39754e6255b..870960e602f9aa113f0ce19eb162b4ceb6632510 100644 (file)
@@ -28,38 +28,28 @@ require_once("connect.inc");
     $stmt = mysqli_stmt_init($link);
     try {
         mysqli_stmt_attr_set($stmt, 0, 0);
-    } catch (Error $exception) {
-        echo $exception->getMessage() . "\n";
+    } catch (\Throwable $e) {
+        echo get_class($e) . ': ' . $e->getMessage() . PHP_EOL;
     }
 
     $stmt->prepare("SELECT * FROM test");
-
-    mt_srand(microtime(true));
-
-    for ($i = -100; $i < 1000; $i++) {
-        if (in_array($i, $valid_attr))
-            continue;
-        $invalid_attr = $i;
-        if (false !== ($tmp = @mysqli_stmt_attr_set($stmt, $invalid_attr, 0))) {
-            printf("[006a] Expecting boolean/false for attribute %d, got %s/%s\n", $invalid_attr, gettype($tmp), $tmp);
-        }
+    // Invalid Attribute (2nd argument)
+    try {
+        mysqli_stmt_attr_set($stmt, -1, 0);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
     }
-
-    for ($i = 0; $i < 2; $i++) {
-        do {
-            $invalid_attr = mt_rand(-1 * (min(4294967296, PHP_INT_MAX) + 1), min(4294967296, PHP_INT_MAX));
-        } while (in_array($invalid_attr, $valid_attr));
-        if (false !== ($tmp = @mysqli_stmt_attr_set($stmt, $invalid_attr, 0))) {
-            printf("[006b] Expecting boolean/false for attribute %d, got %s/%s\n", $invalid_attr, gettype($tmp), $tmp);
-        }
+    // Invalid mode for MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH
+    try {
+        $stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
     }
     $stmt->close();
 
     //
     // MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH
     //
-
-
     // expecting max_length not to be set and be 0 in all cases
     $stmt = mysqli_stmt_init($link);
     $stmt->prepare("SELECT label FROM test");
@@ -79,7 +69,7 @@ require_once("connect.inc");
     // expecting max_length to _be_ set
     $stmt = mysqli_stmt_init($link);
     $stmt->prepare("SELECT label FROM test");
-    $stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, 1);
+    var_dump($stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, 1));
     $res = $stmt->attr_get(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH);
     if ($res !== 1)
         printf("[007.1] max_length should be 1, got %s\n", $res);
@@ -122,21 +112,15 @@ require_once("connect.inc");
 
     if (mysqli_get_client_version() > 50003) {
 
-        $cursor_types = array(
-            MYSQLI_CURSOR_TYPE_NO_CURSOR,
-            MYSQLI_CURSOR_TYPE_READ_ONLY,
-            MYSQLI_CURSOR_TYPE_FOR_UPDATE,
-            MYSQLI_CURSOR_TYPE_SCROLLABLE
-        );
-        do {
-            $invalid_cursor_type = mt_rand(-1000, 1000);
-        } while (in_array($invalid_cursor_type, $cursor_types));
-
         $stmt = mysqli_stmt_init($link);
         $stmt->prepare("SELECT id, label FROM test");
 
-        if (false !== ($tmp = @$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, $invalid_cursor_type)))
-            printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+        // Invalid cursor type
+        try {
+            $stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, -1);
+        } catch (\ValueError $e) {
+            echo $e->getMessage() . \PHP_EOL;
+        }
 
         if (false !== ($tmp = $stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_FOR_UPDATE)))
             printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
@@ -209,6 +193,13 @@ require_once("connect.inc");
 
         $stmt = mysqli_stmt_init($link);
         $stmt->prepare("SELECT id, label FROM test");
+        // Invalid prefetch value
+        try {
+            $stmt->attr_set(MYSQLI_STMT_ATTR_PREFETCH_ROWS, 0);
+        } catch (\ValueError $e) {
+            echo $e->getMessage() . \PHP_EOL;
+        }
+
         if (true !== ($tmp = $stmt->attr_set(MYSQLI_STMT_ATTR_PREFETCH_ROWS, 1)))
             printf("[020] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
         $stmt->execute();
@@ -262,5 +253,10 @@ require_once("connect.inc");
        require_once("clean_table.inc");
 ?>
 --EXPECT--
-mysqli_stmt object is not fully initialized
+Error: mysqli_stmt object is not fully initialized
+mysqli_stmt_attr_set(): Argument #2 ($attr) must be one of MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE
+mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be 0 or 1 for attribute MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH
+bool(true)
+mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be one of MYSQLI_CURSOR_TYPE_NO_CURSOR, MYSQLI_CURSOR_TYPE_READ_ONLY, MYSQLI_CURSOR_TYPE_FOR_UPDATE, or MYSQLI_CURSOR_TYPE_SCROLLABLE for attribute MYSQLI_STMT_ATTR_CURSOR_TYPE
+mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be greater than 0 for attribute MYSQLI_STMT_ATTR_PREFETCH_ROWS
 done!
index aba40decf45254c252a376b994473127e68f446a..a12e01dc4203a13fad010d3ca9acfab4bf8d0153 100644 (file)
@@ -32,35 +32,77 @@ require_once('skipifconnectfailure.inc');
     libmysql gives a less descriptive error message but mysqlnd,
     we did not unify the error messages but ignore this slight difference silently
     */
-    if (!false === ($tmp = @mysqli_stmt_bind_param($stmt, " ", $tmp)))
-        printf("[003d] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, " ", $tmp)))
+            printf("[003d] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
-    if (!false === ($tmp = @mysqli_stmt_bind_param($stmt, "", $id, $label)))
-        printf("[003a] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "", $id, $label)))
+            printf("[003a] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     /* TODO: somehwhat undocumented syntax! */
     $param = array($id);
-    if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "is", $param)))
-        printf("[003b] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "is", $param)))
+         printf("[003b] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     $param = array($id, $label, $id);
-    if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "is", $param)))
-        printf("[003c] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, " ", $tmp)))
+            printf("[003d] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+    try {
+        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "is", $param)))
+            printf("[003c] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
-    if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "a", $id)))
-        printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "a", $id)))
+            printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
-    if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "a", $id, $label)))
-        printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "a", $id, $label)))
+            printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
-    if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "aa", $id, $label)))
-        printf("[006] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    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) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
-    if (!false === ($tmp = mysqli_stmt_bind_param($stmt, "ia", $id, $label)))
-        printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    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) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
-    if (!true === ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label)))
-        printf("[008] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        if (!true === ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label)))
+            printf("[008] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (function_exists("memory_get_usage")) {
         $mem = memory_get_usage();
@@ -374,13 +416,13 @@ require_once('skipifconnectfailure.inc');
        require_once("clean_table.inc");
 ?>
 --EXPECTF--
-Warning: mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables in %s on line %d
-
-Warning: mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables in %s on line %d
-
-Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in %s on line %d
-
-Warning: mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables in %s on line %d
+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
+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
+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
 
index c1dddca4f294baee5b81ac0fc35b9c45e4d58862..f9556ad0f638071dea0cbd57a0b3c78cf60ccadf 100644 (file)
@@ -31,14 +31,20 @@ require_once('skipifconnectfailure.inc');
     if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 1"))
         printf("[004] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
 
-    if (false !== ($tmp = mysqli_stmt_bind_result($stmt, $id)))
-        printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_stmt_bind_result($stmt, $id);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . PHP_EOL;
+    }
 
     if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label)))
         printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
 
-    if (false !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label, $foo)))
-        printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_stmt_bind_result($stmt, $id, $label, $foo);
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . PHP_EOL;
+    }
 
     if (!mysqli_stmt_execute($stmt))
         printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
@@ -290,8 +296,11 @@ require_once('skipifconnectfailure.inc');
         printf("[3001] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
 
     $id = null;
-    if (false !== @mysqli_stmt_bind_result($stmt, $id))
-        printf("[3002] Bind result should not be allowed");
+    try {
+        mysqli_stmt_bind_result($stmt, $id);
+    } catch (\ArgumentCountError $e) {
+        $e->getMessage() . \PHP_EOL;
+    }
 
     mysqli_stmt_close($stmt);
 
@@ -304,10 +313,8 @@ require_once('skipifconnectfailure.inc');
 ?>
 --EXPECTF--
 mysqli_stmt object is not fully initialized
-
-Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in %s on line %d
-
-Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in %s on line %d
+Number of bind variables doesn't match number of fields in prepared statement
+Number of bind variables doesn't match number of fields in prepared statement
 int(1)
 %s(1) "a"
 done!
index 72d807512f730dd2b837741504b76cf3e4a0cc26..55946007477927d6b540d533fb3b2aac21402ff2 100644 (file)
@@ -59,8 +59,11 @@ require_once('skipifconnectfailure.inc');
 
     var_dump($id);
 
-    if (false !== ($tmp = mysqli_stmt_data_seek($stmt, -1)))
-        printf("[015] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        mysqli_stmt_data_seek($stmt, -1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (mysqli_stmt_fetch($stmt))
         printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
@@ -87,8 +90,7 @@ mysqli_stmt object is not fully initialized
 int(3)
 int(1)
 int(1)
-
-Warning: mysqli_stmt_data_seek(): Offset must be positive in %s on line %d
+mysqli_stmt_data_seek(): Argument #2 ($offset) must be greater than or equal to 0
 int(1)
 mysqli_stmt object is already closed
 done!
index c65330ebc951e937b04de1a5cd5b3b1b5dda36a3..7cbbc74988e9b2aadda7cc1022bbd415968db503 100644 (file)
@@ -44,8 +44,12 @@ if ($IS_MYSQLND) {
         printf("[008] More results: %s\n", (mysqli_more_results($link) ? "yes" : "no"));
         printf("[009] Next results: %s\n", (mysqli_next_result($link) ? "yes" : "no"));
 
-        if (!mysqli_stmt_bind_result($stmt, $ver_out) || !mysqli_stmt_fetch($stmt))
-            printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+        try {
+            if (!mysqli_stmt_bind_result($stmt, $ver_out) || !mysqli_stmt_fetch($stmt))
+                printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+        } catch (\ArgumentCountError $e) {
+            echo $e->getMessage() . \PHP_EOL;
+        }
 
         if ("myversion" !== $ver_out)
             printf("[011] Results seem wrong got '%s'\n", $ver_out);
index 51afb04e1b6f9e6227504780f36235533d0967e9..5c725cd063109c5e6a716368ad7006f2d338d65d 100644 (file)
@@ -51,8 +51,12 @@ require_once('skipifconnectfailure.inc');
         printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
 
     $label = null;
-    if (mysqli_stmt_bind_param($stmt, "s", $label))
-        printf("[014] expected error - got ok\n");
+    try {
+        if (mysqli_stmt_bind_param($stmt, "s", $label))
+            printf("[014] expected error - got ok\n");
+    } catch (\ArgumentCountError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
     while (mysqli_stmt_fetch($stmt))
         if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
             printf("[015] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
@@ -91,11 +95,10 @@ require_once('skipifconnectfailure.inc');
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
+--EXPECT--
 mysqli_stmt object is not fully initialized
 mysqli_stmt object is not fully initialized
-
-Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in %s on line %d
+The number of variables must match the number of parameters in the prepared statement
 mysqli_stmt object is already closed
 mysqli_stmt object is already closed
 done!
index cb95ed896afbe852d25bd60711197d399f2c7409..9e6ddec044b4fc3204650c60c8a4a860899f5f16 100644 (file)
@@ -182,11 +182,19 @@ if (!function_exists('mysqli_stmt_get_result'))
                 printf("[032] Expecting %s/%s got %s/%s\n",
                     gettype($pos), $pos, gettype($tmp), $tmp);
         } else {
-
-            if (false !== @mysqli_field_seek($res, $pos))
-                printf("[033] field_seek(%d) did not fail\n", $pos);
-            if (false !== @mysqli_field_seek($res_meta, $pos))
-                printf("[034] field_seek(%d) did not fail\n", $pos);
+            try {
+                $tmp = @mysqli_field_seek($res, $pos);
+                if ($pos >= $num && $tmp !== false) {
+                    printf("[033] field_seek(%d) did not fail\n", $pos);
+                }
+            } catch (ValueError $e) { /* Suppress output because pos is RANDOM */}
+
+            try {
+                $tmp = @mysqli_field_seek($res_meta, $pos);
+                if ($pos >= $num && $tmp !== false) {
+                    printf("[034] field_seek(%d) did not fail\n", $pos);
+                }
+            } catch (ValueError $e) { /* Suppress output because pos is RANDOM */}
         }
     }
 
index 68dad8b2817314bf3e098ceecea902e7f2dd398a..cf9e634cc9e31fc074f45adc608d6fd9c86cefda 100644 (file)
@@ -61,8 +61,11 @@ if (!function_exists('mysqli_stmt_get_result'))
         }
     }
 
-    if (false !== ($tmp = $res->data_seek(-1)))
-        printf("[011] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp);
+    try {
+        $res->data_seek(-1);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (false !== ($tmp = $res->data_seek($res->num_rows + 1)))
         printf("[012] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp);
@@ -70,18 +73,20 @@ if (!function_exists('mysqli_stmt_get_result'))
     for ($i = 0; $i < 100; $i++) {
         /* intentionally out of range! */
         $pos = mt_rand(-1, 4);
-        $tmp = mysqli_data_seek($res, $pos);
-        if (($pos >= 0 && $pos < 3)) {
-            if (true !== $tmp)
-                printf("[015] Expecting boolan/true got %s/%s\n", gettype($tmp), $tmp);
-            $row = $res->fetch_array(MYSQLI_NUM);
-            if ($row[0] !== $pos + 1)
-                printf("[016] Expecting id = %d for pos %d got %s/%s\n",
-                    $pos + 1, $pos, gettype($row[0]), $row[0]);
-        } else {
-            if (false !== $tmp)
-                printf("[014] Expecting boolan/false got %s/%s\n", gettype($tmp), $tmp);
-        }
+        try {
+            $tmp = @mysqli_data_seek($res, $pos);
+            if (($pos >= 0 && $pos < 3)) {
+                if (true !== $tmp)
+                    printf("[015] Expecting boolan/true got %s/%s\n", gettype($tmp), $tmp);
+                $row = $res->fetch_array(MYSQLI_NUM);
+                if ($row[0] !== $pos + 1)
+                    printf("[016] Expecting id = %d for pos %d got %s/%s\n",
+                        $pos + 1, $pos, gettype($row[0]), $row[0]);
+            } else {
+                if (false !== $tmp)
+                    printf("[014] Expecting boolan/false got %s/%s\n", gettype($tmp), $tmp);
+            }
+        } catch (\ValueError $e) { /* Suppress because RANDOM */}
     }
 
     mysqli_stmt_close($stmt);
@@ -127,6 +132,7 @@ if (!function_exists('mysqli_stmt_get_result'))
        require_once("clean_table.inc");
 ?>
 --EXPECT--
+mysqli_result::data_seek(): Argument #1 ($offset) must be greater than or equal to 0
 mysqli_result object is already closed
 mysqli_result object is already closed
 mysqli_result object is already closed
index 00afa5513df796b2b9909731704e6a7aa856a768..705f19e8c21782cc12b079e6d019662beddf21c9 100644 (file)
@@ -64,9 +64,11 @@ require_once('skipifconnectfailure.inc');
     */
     assert(strlen($blob) <= $max_allowed_packet);
 
-    if (false !== ($tmp = mysqli_stmt_send_long_data($stmt, -1, $blob)))
-        printf("[012] Expecting boolean/false, got %s/%s. [%d] %s\n",
-            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+    try {
+        $tmp = mysqli_stmt_send_long_data($stmt, -1, $blob);
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     if (false !== ($tmp = mysqli_stmt_send_long_data($stmt, 999, $blob)))
         printf("[014] Expecting boolean/false, got %s/%s. [%d] %s\n",
@@ -106,6 +108,6 @@ require_once('skipifconnectfailure.inc');
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
-Warning: mysqli_stmt_send_long_data(): Invalid parameter number in %s on line %d
+--EXPECT--
+mysqli_stmt_send_long_data(): Argument #2 ($param_nr) must be greater than or equal to 0
 done!
index 136e2c5d4d9a564ff5f77e6741b285ed0bc428ef..c431a05a60c26209b551e96761c9ed6627d814db 100644 (file)
@@ -63,12 +63,16 @@ mysqlnd.fetch_data_copy=0
     $no_result = 0;
     for ($i = 0; $i < 1000; $i++) {
         $idx = mt_rand(-100, 100);
-        if (true === @mysqli_data_seek($res, $idx)) {
-            $row = $res->fetch_assoc();
-            if (!isset($row['id']) || !isset($row['label'])) {
-                printf("[010] Brute force seek %d returned %d\n", $idx, var_export($row, true));
+        try {
+            if (true === @mysqli_data_seek($res, $idx)) {
+                $row = $res->fetch_assoc();
+                if (!isset($row['id']) || !isset($row['label'])) {
+                    printf("[010] Brute force seek %d returned %d\n", $idx, var_export($row, true));
+                }
+            } else {
+                $no_result++;
             }
-        } else {
+        } catch (\ValueError $e) {
             $no_result++;
         }
     }
index 1b679d142d3a4a2baa6c460a99edcf69d439d720..c309d3e3910b58ac587f173b47aa51f767c4342f 100644 (file)
@@ -19,9 +19,11 @@ require_once('skipifconnectfailure.inc');
         printf("[004] Expecting object, got %s/%s. [%d] %s\n",
             gettype($res), $res, mysqli_errno($link), mysqli_error($link));
 
-    if (false !== ($tmp = mysqli_data_seek($res, 2)))
-        printf("[005] Expecting boolean/true, got %s/%s. [%d] %s\n",
-            gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
+    try {
+        var_dump(mysqli_data_seek($res, 2));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 
     mysqli_free_result($res);
 
@@ -53,7 +55,7 @@ require_once('skipifconnectfailure.inc');
 <?php
        require_once("clean_table.inc");
 ?>
---EXPECTF--
-Warning: mysqli_data_seek(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
+--EXPECT--
+mysqli_data_seek() cannot be used with MYSQLI_USE_RESULT
 mysqli object is already closed
 done!
index 90fb4d9b73f57383480f4539c6466763289e9bd2..04d3b50ecde3fe620527d5f266506b39dd7e4e72 100644 (file)
@@ -488,7 +488,6 @@ static const func_info_t func_infos[] = {
        F1("mysqli_prepare",                                            MAY_BE_FALSE | MAY_BE_OBJECT),
        F1("mysqli_real_escape_string",                         MAY_BE_STRING),
        F1("mysqli_stmt_affected_rows",                         MAY_BE_LONG | MAY_BE_STRING),
-       F0("mysqli_stmt_data_seek",                                     MAY_BE_NULL | MAY_BE_FALSE),
        F1("mysqli_stmt_insert_id",                                     MAY_BE_LONG | MAY_BE_STRING),
        F1("mysqli_stmt_num_rows",                                      MAY_BE_LONG | MAY_BE_STRING),
        F1("mysqli_sqlstate",                                           MAY_BE_NULL | MAY_BE_STRING),