Skip to content

Commit 49d3dde

Browse files
authored
Declare true return types (#8759)
1 parent 2d98631 commit 49d3dde

File tree

11 files changed

+72
-101
lines changed

11 files changed

+72
-101
lines changed

Zend/Optimizer/zend_func_infos.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ static const func_info_t func_infos[] = {
77
F1("get_class_methods", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
88
F1("get_included_files", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
99
FN("set_error_handler", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_OBJECT|MAY_BE_NULL),
10-
F0("restore_error_handler", MAY_BE_TRUE),
1110
FN("set_exception_handler", MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_OBJECT|MAY_BE_NULL),
12-
F0("restore_exception_handler", MAY_BE_TRUE),
1311
F1("get_declared_classes", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1412
F1("get_declared_traits", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1513
F1("get_declared_interfaces", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
@@ -268,10 +266,8 @@ static const func_info_t func_infos[] = {
268266
#endif
269267
F1("mysqli_affected_rows", MAY_BE_LONG|MAY_BE_STRING),
270268
F1("mysqli_character_set_name", MAY_BE_STRING),
271-
F0("mysqli_close", MAY_BE_TRUE),
272269
F1("mysqli_connect", MAY_BE_OBJECT|MAY_BE_FALSE),
273270
F1("mysqli_connect_error", MAY_BE_STRING|MAY_BE_NULL),
274-
F0("mysqli_debug", MAY_BE_TRUE),
275271
F1("mysqli_error", MAY_BE_STRING),
276272
F1("mysqli_error_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY),
277273
F1("mysqli_fetch_field", MAY_BE_OBJECT|MAY_BE_FALSE),
@@ -300,7 +296,6 @@ static const func_info_t func_infos[] = {
300296
F1("mysqli_real_escape_string", MAY_BE_STRING),
301297
F1("mysqli_reap_async_query", MAY_BE_OBJECT|MAY_BE_BOOL),
302298
F1("mysqli_stmt_affected_rows", MAY_BE_LONG|MAY_BE_STRING),
303-
F0("mysqli_stmt_close", MAY_BE_TRUE),
304299
F1("mysqli_stmt_error", MAY_BE_STRING),
305300
F1("mysqli_stmt_error_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY),
306301
F1("mysqli_stmt_get_result", MAY_BE_OBJECT|MAY_BE_FALSE),
@@ -311,7 +306,6 @@ static const func_info_t func_infos[] = {
311306
F1("mysqli_stmt_result_metadata", MAY_BE_OBJECT|MAY_BE_FALSE),
312307
F1("mysqli_stmt_sqlstate", MAY_BE_STRING),
313308
F1("mysqli_sqlstate", MAY_BE_STRING),
314-
F0("mysqli_ssl_set", MAY_BE_TRUE),
315309
F1("mysqli_stat", MAY_BE_STRING|MAY_BE_FALSE),
316310
F1("mysqli_store_result", MAY_BE_OBJECT|MAY_BE_FALSE),
317311
F1("mysqli_use_result", MAY_BE_OBJECT|MAY_BE_FALSE),
@@ -438,7 +432,6 @@ static const func_info_t func_infos[] = {
438432
F1("socket_addrinfo_explain", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY),
439433
FN("sodium_crypto_kx_client_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
440434
FN("sodium_crypto_kx_server_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
441-
F0("sodium_crypto_generichash_update", MAY_BE_TRUE),
442435
#if defined(crypto_secretstream_xchacha20poly1305_ABYTES)
443436
FN("sodium_crypto_secretstream_xchacha20poly1305_init_push", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
444437
#endif
@@ -455,20 +448,9 @@ static const func_info_t func_infos[] = {
455448
F1("ob_get_clean", MAY_BE_STRING|MAY_BE_FALSE),
456449
F1("ob_list_handlers", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
457450
F1("ob_get_status", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY),
458-
F0("krsort", MAY_BE_TRUE),
459-
F0("ksort", MAY_BE_TRUE),
460-
F0("asort", MAY_BE_TRUE),
461-
F0("arsort", MAY_BE_TRUE),
462-
F0("sort", MAY_BE_TRUE),
463-
F0("usort", MAY_BE_TRUE),
464-
F0("uasort", MAY_BE_TRUE),
465-
F0("uksort", MAY_BE_TRUE),
466-
F0("array_walk", MAY_BE_TRUE),
467-
F0("array_walk_recursive", MAY_BE_TRUE),
468451
F1("compact", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
469452
FN("array_fill", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY),
470453
F1("array_fill_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
471-
F0("shuffle", MAY_BE_TRUE),
472454
F1("array_replace", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
473455
F1("array_replace_recursive", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
474456
FN("array_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING),
@@ -544,12 +526,6 @@ static const func_info_t func_infos[] = {
544526
F1("md5_file", MAY_BE_STRING|MAY_BE_FALSE),
545527
F1("sha1", MAY_BE_STRING),
546528
F1("sha1_file", MAY_BE_STRING|MAY_BE_FALSE),
547-
#if defined(HAVE_SYSLOG_H)
548-
F0("closelog", MAY_BE_TRUE),
549-
#endif
550-
#if defined(HAVE_SYSLOG_H)
551-
F0("syslog", MAY_BE_TRUE),
552-
#endif
553529
#if defined(HAVE_INET_NTOP)
554530
F1("inet_ntop", MAY_BE_STRING|MAY_BE_FALSE),
555531
#endif
@@ -639,9 +615,7 @@ static const func_info_t func_infos[] = {
639615
F1("image_type_to_extension", MAY_BE_STRING|MAY_BE_FALSE),
640616
F1("getimagesize", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
641617
F1("getimagesizefromstring", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
642-
F0("phpinfo", MAY_BE_TRUE),
643618
F1("phpversion", MAY_BE_STRING|MAY_BE_FALSE),
644-
F0("phpcredits", MAY_BE_TRUE),
645619
F1("php_sapi_name", MAY_BE_STRING|MAY_BE_FALSE),
646620
F1("php_uname", MAY_BE_STRING),
647621
F1("php_ini_scanned_files", MAY_BE_STRING|MAY_BE_FALSE),

Zend/zend_builtin_functions.stub.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,12 @@ function user_error(string $message, int $error_level = E_USER_NOTICE): bool {}
102102
/** @return callable|null */
103103
function set_error_handler(?callable $callback, int $error_levels = E_ALL) {}
104104

105-
/** @return true */
106-
function restore_error_handler(): bool {}
105+
function restore_error_handler(): true {}
107106

108107
/** @return callable|null */
109108
function set_exception_handler(?callable $callback) {}
110109

111-
/** @return true */
112-
function restore_exception_handler(): bool {}
110+
function restore_exception_handler(): true {}
113111

114112
/**
115113
* @return array<int, string>

Zend/zend_builtin_functions_arginfo.h

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/gen_stub.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ public static function fromNode(Node $node): SimpleType {
188188
return new SimpleType($node->toLowerString(), true);
189189
}
190190

191+
if ($node->toLowerString() === 'true') {
192+
// TODO PHP-Parser doesn't yet recognize true as a stand-alone built-in type
193+
return new SimpleType($node->toLowerString(), true);
194+
}
195+
191196
if ($node->toLowerString() === 'self') {
192197
throw new Exception('The exact class name must be used instead of "self"');
193198
}
@@ -380,6 +385,8 @@ public function toTypeCode(): string {
380385
return "IS_NULL";
381386
case "false":
382387
return "IS_FALSE";
388+
case "true":
389+
return "IS_TRUE";
383390
default:
384391
throw new Exception("Not implemented: $this->name");
385392
}
@@ -393,6 +400,8 @@ public function toTypeMask(): string {
393400
return "MAY_BE_NULL";
394401
case "false":
395402
return "MAY_BE_FALSE";
403+
case "true":
404+
return "MAY_BE_TRUE";
396405
case "bool":
397406
return "MAY_BE_BOOL";
398407
case "int":
@@ -443,6 +452,8 @@ public function toOptimizerTypeMaskForArrayValue(): string {
443452
return "MAY_BE_ARRAY_OF_NULL";
444453
case "false":
445454
return "MAY_BE_ARRAY_OF_FALSE";
455+
case "true":
456+
return "MAY_BE_ARRAY_OF_TRUE";
446457
case "bool":
447458
return "MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE";
448459
case "int":
@@ -472,8 +483,6 @@ public function toOptimizerTypeMask(): string {
472483
}
473484

474485
switch ($this->name) {
475-
case "true":
476-
return "MAY_BE_TRUE";
477486
case "resource":
478487
return "MAY_BE_RESOURCE";
479488
case "callable":

ext/mysqli/mysqli.stub.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,7 @@ function mysqli_change_user(mysqli $mysql, string $username, string $password, ?
749749
/** @refcount 1 */
750750
function mysqli_character_set_name(mysqli $mysql): string {}
751751

752-
/** @return true */
753-
function mysqli_close(mysqli $mysql): bool {} // TODO make return type void
752+
function mysqli_close(mysqli $mysql): true {} // TODO make return type void
754753

755754
function mysqli_commit(mysqli $mysql, int $flags = 0, ?string $name = null): bool {}
756755

@@ -776,8 +775,7 @@ function mysqli_data_seek(mysqli_result $result, int $offset): bool {}
776775

777776
function mysqli_dump_debug_info(mysqli $mysql): bool {}
778777

779-
/** @return true */
780-
function mysqli_debug(string $options): bool {} // TODO make return type void
778+
function mysqli_debug(string $options): true {} // TODO make return type void
781779

782780
function mysqli_errno(mysqli $mysql): int {}
783781

@@ -976,8 +974,7 @@ function mysqli_stmt_bind_param(mysqli_stmt $statement, string $types, mixed &..
976974

977975
function mysqli_stmt_bind_result(mysqli_stmt $statement, mixed &...$vars): bool {}
978976

979-
/** @return true */
980-
function mysqli_stmt_close(mysqli_stmt $statement): bool {}
977+
function mysqli_stmt_close(mysqli_stmt $statement): true {}
981978

982979
function mysqli_stmt_data_seek(mysqli_stmt $statement, int $offset): void {}
983980

@@ -1036,15 +1033,14 @@ function mysqli_stmt_sqlstate(mysqli_stmt $statement): string {}
10361033
/** @refcount 1 */
10371034
function mysqli_sqlstate(mysqli $mysql): string {}
10381035

1039-
/** @return true */
10401036
function mysqli_ssl_set(
10411037
mysqli $mysql,
10421038
?string $key,
10431039
?string $certificate,
10441040
?string $ca_certificate,
10451041
?string $ca_path,
10461042
?string $cipher_algos
1047-
): bool {} // TODO make return type void
1043+
): true {} // TODO make return type void
10481044

10491045
/** @refcount 1 */
10501046
function mysqli_stat(mysqli $mysql): string|false {}

ext/mysqli/mysqli_arginfo.h

Lines changed: 17 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/sodium/libsodium.stub.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ function sodium_crypto_generichash_keygen(): string {}
152152
/** @sensitive-param $key */
153153
function sodium_crypto_generichash_init(string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {}
154154

155-
/** @return true */
156-
function sodium_crypto_generichash_update(string &$state, string $message): bool {}
155+
function sodium_crypto_generichash_update(string &$state, string $message): true {}
157156

158157
function sodium_crypto_generichash_final(string &$state, int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {}
159158

ext/sodium/libsodium_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)