Skip to content

Commit 73f989a

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix/improve mysqli stubs
2 parents 9052f3b + 44a311d commit 73f989a

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
/**
@@ -341,7 +341,7 @@ public function fetch_fields() {}
341341
public function fetch_field_direct(int $index) {}
342342

343343
/**
344-
* @return array|false
344+
* @return array
345345
* @alias mysqli_fetch_all
346346
*/
347347
public function fetch_all(int $mode = MYSQLI_NUM) {}
@@ -390,7 +390,7 @@ class mysqli_stmt
390390
public function __construct(mysqli $mysql, ?string $query = null) {}
391391

392392
/**
393-
* @return int|false
393+
* @return int
394394
* @alias mysqli_stmt_attr_get
395395
*/
396396
public function attr_get(int $attribute) {}
@@ -527,11 +527,11 @@ function mysqli_begin_transaction(mysqli $mysql, int $flags = 0, ?string $name =
527527

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

530-
function mysqli_character_set_name(mysqli $mysql): ?string {}
530+
function mysqli_character_set_name(mysqli $mysql): string {}
531531

532532
function mysqli_close(mysqli $mysql): bool {}
533533

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

536536
function mysqli_connect(
537537
?string $hostname = null,
@@ -554,7 +554,7 @@ function mysqli_debug(string $options): bool {}
554554

555555
function mysqli_errno(mysqli $mysql): int {}
556556

557-
function mysqli_error(mysqli $mysql): ?string {}
557+
function mysqli_error(mysqli $mysql): string {}
558558

559559
function mysqli_error_list(mysqli $mysql): array {}
560560

@@ -571,15 +571,15 @@ function mysqli_fetch_field_direct(mysqli_result $result, int $index): object|fa
571571

572572
function mysqli_fetch_lengths(mysqli_result $result): array|false {}
573573

574-
function mysqli_fetch_all(mysqli_result $result, int $mode = MYSQLI_NUM): array|false {}
574+
function mysqli_fetch_all(mysqli_result $result, int $mode = MYSQLI_NUM): array {}
575575

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

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

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

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

584584
function mysqli_field_count(mysqli $mysql): int {}
585585

@@ -634,10 +634,16 @@ function mysqli_num_rows(mysqli_result $result): int|string {}
634634
/** @param string|int $value */
635635
function mysqli_options(mysqli $mysql, int $option, $value): bool {}
636636

637+
/**
638+
* @param string|int $value
639+
* @alias mysqli_options
640+
*/
641+
function mysqli_set_opt(mysqli $mysql, int $option, $value): bool {}
642+
637643
function mysqli_ping(mysqli $mysql): bool {}
638644

639645
#if defined(MYSQLI_USE_MYSQLND)
640-
function mysqli_poll(?array &$read, ?array &$write, array &$error, int $seconds, int $microseconds = 0): int|false {}
646+
function mysqli_poll(?array &$read, ?array &$error, array &$reject, int $seconds, int $microseconds = 0): int|false {}
641647
#endif
642648

643649
function mysqli_prepare(mysqli $mysql, string $query): mysqli_stmt|false {}
@@ -659,6 +665,9 @@ function mysqli_real_connect(
659665

660666
function mysqli_real_escape_string(mysqli $mysql, string $string): string {}
661667

668+
/** @alias mysqli_real_escape_string */
669+
function mysqli_escape_string(mysqli $mysql, string $string): string {}
670+
662671
function mysqli_real_query(mysqli $mysql, string $query): bool {}
663672

664673
#if defined(MYSQLI_USE_MYSQLND)
@@ -691,7 +700,7 @@ function mysqli_stmt_data_seek(mysqli_stmt $statement, int $offset): void {}
691700

692701
function mysqli_stmt_errno(mysqli_stmt $statement): int {}
693702

694-
function mysqli_stmt_error(mysqli_stmt $statement): ?string {}
703+
function mysqli_stmt_error(mysqli_stmt $statement): string {}
695704

696705
function mysqli_stmt_error_list(mysqli_stmt $statement): array {}
697706

@@ -731,9 +740,9 @@ function mysqli_stmt_send_long_data(mysqli_stmt $statement, int $param_num, stri
731740

732741
function mysqli_stmt_store_result(mysqli_stmt $statement): bool {}
733742

734-
function mysqli_stmt_sqlstate(mysqli_stmt $statement): ?string {}
743+
function mysqli_stmt_sqlstate(mysqli_stmt $statement): string {}
735744

736-
function mysqli_sqlstate(mysqli $mysql): ?string {}
745+
function mysqli_sqlstate(mysqli $mysql): string {}
737746

738747
function mysqli_ssl_set(
739748
mysqli $mysql,
@@ -757,12 +766,3 @@ function mysqli_use_result(mysqli $mysql): mysqli_result|false {}
757766
function mysqli_warning_count(mysqli $mysql): int {}
758767

759768
function mysqli_refresh(mysqli $mysql, int $flags): bool {}
760-
761-
/** @alias mysqli_real_escape_string */
762-
function mysqli_escape_string(mysqli $mysql, string $string): string {}
763-
764-
/**
765-
* @param string|int $value
766-
* @alias mysqli_options
767-
*/
768-
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

@@ -2149,16 +2138,12 @@ PHP_FUNCTION(mysqli_sqlstate)
21492138
{
21502139
MY_MYSQL *mysql;
21512140
zval *mysql_link;
2152-
const char *state;
21532141

21542142
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
21552143
RETURN_THROWS();
21562144
}
21572145
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
2158-
state = mysql_sqlstate(mysql->mysql);
2159-
if (state) {
2160-
RETURN_STRING(state);
2161-
}
2146+
RETURN_STRING(mysql_sqlstate(mysql->mysql));
21622147
}
21632148
/* }}} */
21642149

@@ -2358,17 +2343,13 @@ PHP_FUNCTION(mysqli_stmt_error)
23582343
{
23592344
MY_STMT *stmt;
23602345
zval *mysql_stmt;
2361-
const char * err;
23622346

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

2368-
err = mysql_stmt_error(stmt->stmt);
2369-
if (err) {
2370-
RETURN_STRING(err);
2371-
}
2352+
RETURN_STRING(mysql_stmt_error(stmt->stmt));
23722353
}
23732354
/* }}} */
23742355

@@ -2499,17 +2480,13 @@ PHP_FUNCTION(mysqli_stmt_sqlstate)
24992480
{
25002481
MY_STMT *stmt;
25012482
zval *mysql_stmt;
2502-
const char * state;
25032483

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

2509-
state = mysql_stmt_sqlstate(stmt->stmt);
2510-
if (state) {
2511-
RETURN_STRING(state);
2512-
}
2489+
RETURN_STRING(mysql_stmt_sqlstate(stmt->stmt));
25132490
}
25142491
/* }}} */
25152492

0 commit comments

Comments
 (0)