Skip to content

Declare true return types #8759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ static const func_info_t func_infos[] = {
F1("get_class_methods", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
F1("get_included_files", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
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),
F0("restore_error_handler", MAY_BE_TRUE),
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),
F0("restore_exception_handler", MAY_BE_TRUE),
F1("get_declared_classes", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
F1("get_declared_traits", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
F1("get_declared_interfaces", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
Expand Down Expand Up @@ -268,10 +266,8 @@ static const func_info_t func_infos[] = {
#endif
F1("mysqli_affected_rows", MAY_BE_LONG|MAY_BE_STRING),
F1("mysqli_character_set_name", MAY_BE_STRING),
F0("mysqli_close", MAY_BE_TRUE),
F1("mysqli_connect", MAY_BE_OBJECT|MAY_BE_FALSE),
F1("mysqli_connect_error", MAY_BE_STRING|MAY_BE_NULL),
F0("mysqli_debug", MAY_BE_TRUE),
F1("mysqli_error", MAY_BE_STRING),
F1("mysqli_error_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY),
F1("mysqli_fetch_field", MAY_BE_OBJECT|MAY_BE_FALSE),
Expand Down Expand Up @@ -300,7 +296,6 @@ static const func_info_t func_infos[] = {
F1("mysqli_real_escape_string", MAY_BE_STRING),
F1("mysqli_reap_async_query", MAY_BE_OBJECT|MAY_BE_BOOL),
F1("mysqli_stmt_affected_rows", MAY_BE_LONG|MAY_BE_STRING),
F0("mysqli_stmt_close", MAY_BE_TRUE),
F1("mysqli_stmt_error", MAY_BE_STRING),
F1("mysqli_stmt_error_list", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY),
F1("mysqli_stmt_get_result", MAY_BE_OBJECT|MAY_BE_FALSE),
Expand All @@ -311,7 +306,6 @@ static const func_info_t func_infos[] = {
F1("mysqli_stmt_result_metadata", MAY_BE_OBJECT|MAY_BE_FALSE),
F1("mysqli_stmt_sqlstate", MAY_BE_STRING),
F1("mysqli_sqlstate", MAY_BE_STRING),
F0("mysqli_ssl_set", MAY_BE_TRUE),
F1("mysqli_stat", MAY_BE_STRING|MAY_BE_FALSE),
F1("mysqli_store_result", MAY_BE_OBJECT|MAY_BE_FALSE),
F1("mysqli_use_result", MAY_BE_OBJECT|MAY_BE_FALSE),
Expand Down Expand Up @@ -438,7 +432,6 @@ static const func_info_t func_infos[] = {
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),
FN("sodium_crypto_kx_client_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
FN("sodium_crypto_kx_server_session_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
F0("sodium_crypto_generichash_update", MAY_BE_TRUE),
#if defined(crypto_secretstream_xchacha20poly1305_ABYTES)
FN("sodium_crypto_secretstream_xchacha20poly1305_init_push", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
#endif
Expand All @@ -455,20 +448,9 @@ static const func_info_t func_infos[] = {
F1("ob_get_clean", MAY_BE_STRING|MAY_BE_FALSE),
F1("ob_list_handlers", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
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),
F0("krsort", MAY_BE_TRUE),
F0("ksort", MAY_BE_TRUE),
F0("asort", MAY_BE_TRUE),
F0("arsort", MAY_BE_TRUE),
F0("sort", MAY_BE_TRUE),
F0("usort", MAY_BE_TRUE),
F0("uasort", MAY_BE_TRUE),
F0("uksort", MAY_BE_TRUE),
F0("array_walk", MAY_BE_TRUE),
F0("array_walk_recursive", MAY_BE_TRUE),
F1("compact", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
FN("array_fill", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY),
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),
F0("shuffle", MAY_BE_TRUE),
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),
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),
FN("array_keys", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING),
Expand Down Expand Up @@ -544,12 +526,6 @@ static const func_info_t func_infos[] = {
F1("md5_file", MAY_BE_STRING|MAY_BE_FALSE),
F1("sha1", MAY_BE_STRING),
F1("sha1_file", MAY_BE_STRING|MAY_BE_FALSE),
#if defined(HAVE_SYSLOG_H)
F0("closelog", MAY_BE_TRUE),
#endif
#if defined(HAVE_SYSLOG_H)
F0("syslog", MAY_BE_TRUE),
#endif
#if defined(HAVE_INET_NTOP)
F1("inet_ntop", MAY_BE_STRING|MAY_BE_FALSE),
#endif
Expand Down Expand Up @@ -639,9 +615,7 @@ static const func_info_t func_infos[] = {
F1("image_type_to_extension", MAY_BE_STRING|MAY_BE_FALSE),
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),
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),
F0("phpinfo", MAY_BE_TRUE),
F1("phpversion", MAY_BE_STRING|MAY_BE_FALSE),
F0("phpcredits", MAY_BE_TRUE),
F1("php_sapi_name", MAY_BE_STRING|MAY_BE_FALSE),
F1("php_uname", MAY_BE_STRING),
F1("php_ini_scanned_files", MAY_BE_STRING|MAY_BE_FALSE),
Expand Down
6 changes: 2 additions & 4 deletions Zend/zend_builtin_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ function user_error(string $message, int $error_level = E_USER_NOTICE): bool {}
/** @return callable|null */
function set_error_handler(?callable $callback, int $error_levels = E_ALL) {}

/** @return true */
function restore_error_handler(): bool {}
function restore_error_handler(): true {}

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

/** @return true */
function restore_exception_handler(): bool {}
function restore_exception_handler(): true {}

/**
* @return array<int, string>
Expand Down
7 changes: 4 additions & 3 deletions Zend/zend_builtin_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ public static function fromNode(Node $node): SimpleType {
return new SimpleType($node->toLowerString(), true);
}

if ($node->toLowerString() === 'true') {
// TODO PHP-Parser doesn't yet recognize true as a stand-alone built-in type
return new SimpleType($node->toLowerString(), true);
}

if ($node->toLowerString() === 'self') {
throw new Exception('The exact class name must be used instead of "self"');
}
Expand Down Expand Up @@ -380,6 +385,8 @@ public function toTypeCode(): string {
return "IS_NULL";
case "false":
return "IS_FALSE";
case "true":
return "IS_TRUE";
default:
throw new Exception("Not implemented: $this->name");
}
Expand All @@ -393,6 +400,8 @@ public function toTypeMask(): string {
return "MAY_BE_NULL";
case "false":
return "MAY_BE_FALSE";
case "true":
return "MAY_BE_TRUE";
case "bool":
return "MAY_BE_BOOL";
case "int":
Expand Down Expand Up @@ -443,6 +452,8 @@ public function toOptimizerTypeMaskForArrayValue(): string {
return "MAY_BE_ARRAY_OF_NULL";
case "false":
return "MAY_BE_ARRAY_OF_FALSE";
case "true":
return "MAY_BE_ARRAY_OF_TRUE";
case "bool":
return "MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE";
case "int":
Expand Down Expand Up @@ -472,8 +483,6 @@ public function toOptimizerTypeMask(): string {
}

switch ($this->name) {
case "true":
return "MAY_BE_TRUE";
case "resource":
return "MAY_BE_RESOURCE";
case "callable":
Expand Down
12 changes: 4 additions & 8 deletions ext/mysqli/mysqli.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ function mysqli_change_user(mysqli $mysql, string $username, string $password, ?
/** @refcount 1 */
function mysqli_character_set_name(mysqli $mysql): string {}

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

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

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

function mysqli_dump_debug_info(mysqli $mysql): bool {}

/** @return true */
function mysqli_debug(string $options): bool {} // TODO make return type void
function mysqli_debug(string $options): true {} // TODO make return type void

function mysqli_errno(mysqli $mysql): int {}

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

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

/** @return true */
function mysqli_stmt_close(mysqli_stmt $statement): bool {}
function mysqli_stmt_close(mysqli_stmt $statement): true {}

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

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

/** @return true */
function mysqli_ssl_set(
mysqli $mysql,
?string $key,
?string $certificate,
?string $ca_certificate,
?string $ca_path,
?string $cipher_algos
): bool {} // TODO make return type void
): true {} // TODO make return type void

/** @refcount 1 */
function mysqli_stat(mysqli $mysql): string|false {}
Expand Down
30 changes: 17 additions & 13 deletions ext/mysqli/mysqli_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions ext/sodium/libsodium.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ function sodium_crypto_generichash_keygen(): string {}
/** @sensitive-param $key */
function sodium_crypto_generichash_init(string $key = "", int $length = SODIUM_CRYPTO_GENERICHASH_BYTES): string {}

/** @return true */
function sodium_crypto_generichash_update(string &$state, string $message): bool {}
function sodium_crypto_generichash_update(string &$state, string $message): true {}

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

Expand Down
4 changes: 2 additions & 2 deletions ext/sodium/libsodium_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading