Skip to content

Commit 5d3e3a6

Browse files
TysonAndrenikic
authored andcommitted
Be more precise about possible types for mysqli methods
mysqli has an uncommon approach to 64-bit compatibility: it will convert numbers that can't be represented on 32-bit platforms to a string. This is documented at https://www.php.net/manual/en/mysqli-stmt.affected-rows.php#refsect1-mysqli-stmt.affected-rows-returnvalues So if there's a query to a remote mysqli server that affects more than 2.2 billion rows, then the opcache inference might be incorrect. (It's possible to add a MAY_BE_STRING_ON_32_BIT_PLATFORM bitflag macro to account for this, but I don't think there's a need or want to?) Patches 3162285 This is based on the list of php 7.4 functions using MYSQLI_RETURN_LONG_INT in mysqli_api.c
1 parent 07c63c6 commit 5d3e3a6

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,8 +2029,8 @@ PHP_FUNCTION(mysqli_stmt_send_long_data)
20292029
}
20302030
/* }}} */
20312031

2032-
/* {{{ proto mixed mysqli_stmt_affected_rows(object stmt)
2033-
Return the number of rows affected in the last query for the given link */
2032+
/* {{{ proto string|int|false mysqli_stmt_affected_rows(object stmt)
2033+
Return the number of rows affected in the last query for the given link. */
20342034
PHP_FUNCTION(mysqli_stmt_affected_rows)
20352035
{
20362036
MY_STMT *stmt;

ext/mysqli/mysqli_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ PHP_MYSQLI_EXPORT(zend_object *) mysqli_objects_new(zend_class_entry *);
9090
mysql->multi_query = 1; \
9191
}
9292

93+
/* Numbers that cannot be represented as a signed int are converted to a string instead (affects 32-bit builds). */
9394
#define MYSQLI_RETURN_LONG_INT(__val) \
9495
{ \
9596
if ((__val) < ZEND_LONG_MAX) { \

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static const func_info_t func_infos[] = {
10281028
F1("mysqli_fetch_all", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY),
10291029
F1("mysqli_fetch_object", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_OBJECT),
10301030
F0("mysqli_free_result", MAY_BE_NULL),
1031-
F0("mysqli_affected_rows", MAY_BE_NULL | MAY_BE_LONG),
1031+
F1("mysqli_affected_rows", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING),
10321032
F0("mysqli_autocommit", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10331033
F0("mysqli_stmt_bind_param", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10341034
F0("mysqli_stmt_bind_result", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
@@ -1064,14 +1064,14 @@ static const func_info_t func_infos[] = {
10641064
F0("mysqli_get_server_version", MAY_BE_NULL | MAY_BE_LONG),
10651065
F1("mysqli_info", MAY_BE_NULL | MAY_BE_STRING),
10661066
F1("mysqli_init", MAY_BE_FALSE | MAY_BE_OBJECT),
1067-
F0("mysqli_insert_id", MAY_BE_NULL | MAY_BE_LONG),
1067+
F1("mysqli_insert_id", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING),
10681068
F0("mysqli_kill", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10691069
F0("mysqli_more_results", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10701070
F0("mysqli_next_result", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10711071
F0("mysqli_stmt_more_results", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10721072
F0("mysqli_stmt_next_result", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10731073
F0("mysqli_num_fields", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_LONG),
1074-
F0("mysqli_num_rows", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_LONG),
1074+
F1("mysqli_num_rows", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_STRING),
10751075
F0("mysqli_options", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10761076
F0("mysqli_ping", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10771077
F1("mysqli_prepare", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_OBJECT),
@@ -1080,15 +1080,15 @@ static const func_info_t func_infos[] = {
10801080
F1("mysqli_real_escape_string", MAY_BE_NULL | MAY_BE_STRING),
10811081
F0("mysqli_rollback", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10821082
F0("mysqli_stmt_send_long_data", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
1083-
F0("mysqli_stmt_affected_rows", MAY_BE_NULL | MAY_BE_LONG),
1083+
F1("mysqli_stmt_affected_rows", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING),
10841084
F0("mysqli_stmt_close", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10851085
F0("mysqli_stmt_data_seek", MAY_BE_NULL | MAY_BE_FALSE),
10861086
F0("mysqli_stmt_field_count", MAY_BE_NULL | MAY_BE_LONG),
10871087
F0("mysqli_stmt_free_result", MAY_BE_NULL),
1088-
F0("mysqli_stmt_insert_id", MAY_BE_NULL | MAY_BE_LONG),
1088+
F1("mysqli_stmt_insert_id", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING),
10891089
F0("mysqli_stmt_param_count", MAY_BE_NULL | MAY_BE_LONG),
10901090
F0("mysqli_stmt_reset", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
1091-
F0("mysqli_stmt_num_rows", MAY_BE_NULL | MAY_BE_LONG),
1091+
F1("mysqli_stmt_num_rows", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_STRING),
10921092
F0("mysqli_select_db", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
10931093
F1("mysqli_sqlstate", MAY_BE_NULL | MAY_BE_STRING),
10941094
F0("mysqli_ssl_set", MAY_BE_NULL | MAY_BE_TRUE),

0 commit comments

Comments
 (0)