Skip to content

Commit 44a311d

Browse files
kamil-tekielanikic
authored andcommitted
Fix/improve mysqli stubs
* mysqli_commit $flags default value is 0, not -1. * A number of functions cannot actually return null. * mysqli_poll parameter names were incorrect, as this function has a different signature from select. * fetch functions apart from fetch_all can return false on failure.
1 parent 90081c5 commit 44a311d

File tree

4 files changed

+61
-91
lines changed

4 files changed

+61
-91
lines changed

ext/mysqli/mysqli.stub.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function begin_transaction(int $flags = 0, ?string $name = null) {}
3636
public function change_user(string $username, string $password, ?string $database) {}
3737

3838
/**
39-
* @return string|null
39+
* @return string
4040
* @alias mysqli_character_set_name
4141
*/
4242
public function character_set_name() {}
@@ -51,7 +51,7 @@ public function close() {}
5151
* @return bool
5252
* @alias mysqli_commit
5353
*/
54-
public function commit(int $flags = -1, ?string $name = null) {}
54+
public function commit(int $flags = 0, ?string $name = null) {}
5555

5656
/**
5757
* @return mysqli|null|false
@@ -101,7 +101,7 @@ public function get_connection_stats() {}
101101
#endif
102102

103103
/**
104-
* @return string|null
104+
* @return string
105105
* @alias mysqli_get_server_info
106106
*/
107107
public function get_server_info() {}
@@ -152,7 +152,7 @@ public function ping() {}
152152
* @return int|false
153153
* @alias mysqli_poll
154154
*/
155-
public static function poll(?array &$read, ?array &$write, array &$error, int $seconds, int $microseconds = 0) {}
155+
public static function poll(?array &$read, ?array &$error, array &$reject, int $seconds, int $microseconds = 0) {}
156156
#endif
157157

158158
/**
@@ -342,7 +342,7 @@ public function fetch_field_direct(int $index) {}
342342

343343
#if defined(MYSQLI_USE_MYSQLND)
344344
/**
345-
* @return array|false
345+
* @return array
346346
* @alias mysqli_fetch_all
347347
*/
348348
public function fetch_all(int $mode = MYSQLI_NUM) {}
@@ -392,7 +392,7 @@ class mysqli_stmt
392392
public function __construct(mysqli $mysql, ?string $query = null) {}
393393

394394
/**
395-
* @return int|false
395+
* @return int
396396
* @alias mysqli_stmt_attr_get
397397
*/
398398
public function attr_get(int $attribute) {}
@@ -529,11 +529,11 @@ function mysqli_begin_transaction(mysqli $mysql, int $flags = 0, ?string $name =
529529

530530
function mysqli_change_user(mysqli $mysql, string $username, string $password, ?string $database): bool {}
531531

532-
function mysqli_character_set_name(mysqli $mysql): ?string {}
532+
function mysqli_character_set_name(mysqli $mysql): string {}
533533

534534
function mysqli_close(mysqli $mysql): bool {}
535535

536-
function mysqli_commit(mysqli $mysql, int $flags = -1, ?string $name = null): bool {}
536+
function mysqli_commit(mysqli $mysql, int $flags = 0, ?string $name = null): bool {}
537537

538538
function mysqli_connect(
539539
?string $hostname = null,
@@ -556,7 +556,7 @@ function mysqli_debug(string $options): bool {}
556556

557557
function mysqli_errno(mysqli $mysql): int {}
558558

559-
function mysqli_error(mysqli $mysql): ?string {}
559+
function mysqli_error(mysqli $mysql): string {}
560560

561561
function mysqli_error_list(mysqli $mysql): array {}
562562

@@ -574,16 +574,16 @@ function mysqli_fetch_field_direct(mysqli_result $result, int $index): object|fa
574574
function mysqli_fetch_lengths(mysqli_result $result): array|false {}
575575

576576
#if defined(MYSQLI_USE_MYSQLND)
577-
function mysqli_fetch_all(mysqli_result $result, int $mode = MYSQLI_NUM): array|false {}
577+
function mysqli_fetch_all(mysqli_result $result, int $mode = MYSQLI_NUM): array {}
578578
#endif
579579

580580
function mysqli_fetch_array(mysqli_result $result, int $mode = MYSQLI_BOTH): array|null|false {}
581581

582-
function mysqli_fetch_assoc(mysqli_result $result): ?array {}
582+
function mysqli_fetch_assoc(mysqli_result $result): array|null|false {}
583583

584-
function mysqli_fetch_object(mysqli_result $result, string $class = "stdClass", array $constructor_args = []): ?object {}
584+
function mysqli_fetch_object(mysqli_result $result, string $class = "stdClass", array $constructor_args = []): object|null|false {}
585585

586-
function mysqli_fetch_row(mysqli_result $result): ?array {}
586+
function mysqli_fetch_row(mysqli_result $result): array|null|false {}
587587

588588
function mysqli_field_count(mysqli $mysql): int {}
589589

@@ -638,10 +638,16 @@ function mysqli_num_rows(mysqli_result $result): int|string {}
638638
/** @param string|int $value */
639639
function mysqli_options(mysqli $mysql, int $option, $value): bool {}
640640

641+
/**
642+
* @param string|int $value
643+
* @alias mysqli_options
644+
*/
645+
function mysqli_set_opt(mysqli $mysql, int $option, $value): bool {}
646+
641647
function mysqli_ping(mysqli $mysql): bool {}
642648

643649
#if defined(MYSQLI_USE_MYSQLND)
644-
function mysqli_poll(?array &$read, ?array &$write, array &$error, int $seconds, int $microseconds = 0): int|false {}
650+
function mysqli_poll(?array &$read, ?array &$error, array &$reject, int $seconds, int $microseconds = 0): int|false {}
645651
#endif
646652

647653
function mysqli_prepare(mysqli $mysql, string $query): mysqli_stmt|false {}
@@ -663,6 +669,9 @@ function mysqli_real_connect(
663669

664670
function mysqli_real_escape_string(mysqli $mysql, string $string): string {}
665671

672+
/** @alias mysqli_real_escape_string */
673+
function mysqli_escape_string(mysqli $mysql, string $string): string {}
674+
666675
function mysqli_real_query(mysqli $mysql, string $query): bool {}
667676

668677
#if defined(MYSQLI_USE_MYSQLND)
@@ -695,7 +704,7 @@ function mysqli_stmt_data_seek(mysqli_stmt $statement, int $offset): void {}
695704

696705
function mysqli_stmt_errno(mysqli_stmt $statement): int {}
697706

698-
function mysqli_stmt_error(mysqli_stmt $statement): ?string {}
707+
function mysqli_stmt_error(mysqli_stmt $statement): string {}
699708

700709
function mysqli_stmt_error_list(mysqli_stmt $statement): array {}
701710

@@ -735,9 +744,9 @@ function mysqli_stmt_send_long_data(mysqli_stmt $statement, int $param_num, stri
735744

736745
function mysqli_stmt_store_result(mysqli_stmt $statement): bool {}
737746

738-
function mysqli_stmt_sqlstate(mysqli_stmt $statement): ?string {}
747+
function mysqli_stmt_sqlstate(mysqli_stmt $statement): string {}
739748

740-
function mysqli_sqlstate(mysqli $mysql): ?string {}
749+
function mysqli_sqlstate(mysqli $mysql): string {}
741750

742751
function mysqli_ssl_set(
743752
mysqli $mysql,
@@ -761,12 +770,3 @@ function mysqli_use_result(mysqli $mysql): mysqli_result|false {}
761770
function mysqli_warning_count(mysqli $mysql): int {}
762771

763772
function mysqli_refresh(mysqli $mysql, int $flags): bool {}
764-
765-
/** @alias mysqli_real_escape_string */
766-
function mysqli_escape_string(mysqli $mysql, string $string): string {}
767-
768-
/**
769-
* @param string|int $value
770-
* @alias mysqli_options
771-
*/
772-
function mysqli_set_opt(mysqli $mysql, int $option, $value): bool {}

ext/mysqli/mysqli_api.c

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -614,17 +614,13 @@ PHP_FUNCTION(mysqli_character_set_name)
614614
{
615615
MY_MYSQL *mysql;
616616
zval *mysql_link;
617-
const char *cs_name;
618617

619618
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
620619
RETURN_THROWS();
621620
}
622621

623622
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
624-
cs_name = mysql_character_set_name(mysql->mysql);
625-
if (cs_name) {
626-
RETURN_STRING(cs_name);
627-
}
623+
RETURN_STRING(mysql_character_set_name(mysql->mysql));
628624
}
629625
/* }}} */
630626

@@ -801,16 +797,12 @@ PHP_FUNCTION(mysqli_error)
801797
{
802798
MY_MYSQL *mysql;
803799
zval *mysql_link;
804-
const char *err;
805800

806801
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
807802
RETURN_THROWS();
808803
}
809804
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
810-
err = mysql_error(mysql->mysql);
811-
if (err) {
812-
RETURN_STRING(err);
813-
}
805+
RETURN_STRING(mysql_error(mysql->mysql));
814806
}
815807
/* }}} */
816808

@@ -1337,10 +1329,7 @@ PHP_FUNCTION(mysqli_get_client_info)
13371329
}
13381330
}
13391331

1340-
const char * info = mysql_get_client_info();
1341-
if (info) {
1342-
RETURN_STRING(info);
1343-
}
1332+
RETURN_STRING(mysql_get_client_info());
13441333
}
13451334
/* }}} */
13461335

@@ -2151,16 +2140,12 @@ PHP_FUNCTION(mysqli_sqlstate)
21512140
{
21522141
MY_MYSQL *mysql;
21532142
zval *mysql_link;
2154-
const char *state;
21552143

21562144
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
21572145
RETURN_THROWS();
21582146
}
21592147
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
2160-
state = mysql_sqlstate(mysql->mysql);
2161-
if (state) {
2162-
RETURN_STRING(state);
2163-
}
2148+
RETURN_STRING(mysql_sqlstate(mysql->mysql));
21642149
}
21652150
/* }}} */
21662151

@@ -2360,17 +2345,13 @@ PHP_FUNCTION(mysqli_stmt_error)
23602345
{
23612346
MY_STMT *stmt;
23622347
zval *mysql_stmt;
2363-
const char * err;
23642348

23652349
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
23662350
RETURN_THROWS();
23672351
}
23682352
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_INITIALIZED);
23692353

2370-
err = mysql_stmt_error(stmt->stmt);
2371-
if (err) {
2372-
RETURN_STRING(err);
2373-
}
2354+
RETURN_STRING(mysql_stmt_error(stmt->stmt));
23742355
}
23752356
/* }}} */
23762357

@@ -2501,17 +2482,13 @@ PHP_FUNCTION(mysqli_stmt_sqlstate)
25012482
{
25022483
MY_STMT *stmt;
25032484
zval *mysql_stmt;
2504-
const char * state;
25052485

25062486
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) {
25072487
RETURN_THROWS();
25082488
}
25092489
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
25102490

2511-
state = mysql_stmt_sqlstate(stmt->stmt);
2512-
if (state) {
2513-
RETURN_STRING(state);
2514-
}
2491+
RETURN_STRING(mysql_stmt_sqlstate(stmt->stmt));
25152492
}
25162493
/* }}} */
25172494

0 commit comments

Comments
 (0)