Skip to content

Commit 9cf6a54

Browse files
committed
Make mysqli_connect arguments explicitly nullable
It should be possible to skip any of these (and use the ini configured defaults) by passing null, independently of strict_types settings. Noticed while working on GH-4227.
1 parent 8f854c1 commit 9cf6a54

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

ext/mysqli/mysqli_nonapi.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
5858
size_t hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
5959
zend_bool persistent = FALSE;
6060
zend_long port = 0, flags = 0;
61+
zend_bool port_is_null = 1;
6162
zend_string *hash_key = NULL;
6263
zend_bool new_connection = FALSE;
6364
zend_resource *le;
@@ -80,8 +81,8 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
8081
hostname = username = dbname = passwd = socket = NULL;
8182

8283
if (!is_real_connect) {
83-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ssssls", &hostname, &hostname_len, &username, &username_len,
84-
&passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len) == FAILURE) {
84+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!s!l!s!", &hostname, &hostname_len, &username, &username_len,
85+
&passwd, &passwd_len, &dbname, &dbname_len, &port, &port_is_null, &socket, &socket_len) == FAILURE) {
8586
return;
8687
}
8788

@@ -98,9 +99,8 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
9899
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
99100
} else {
100101
/* We have flags too */
101-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|sssslsl", &object, mysqli_link_class_entry,
102-
&hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len,
103-
&flags) == FAILURE) {
102+
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|s!s!s!s!l!s!l", &object, mysqli_link_class_entry,
103+
&hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &port_is_null, &socket, &socket_len, &flags) == FAILURE) {
104104
return;
105105
}
106106

@@ -121,7 +121,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
121121
if (!socket_len || !socket) {
122122
socket = MyG(default_socket);
123123
}
124-
if (!port){
124+
if (port_is_null || !port) {
125125
port = MyG(default_port);
126126
}
127127
if (!passwd) {

0 commit comments

Comments
 (0)