Skip to content

Add more specific array return type hints for various extensions - part 5 #7471

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

Open
wants to merge 2 commits into
base: PHP-8.1
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ static const func_info_t func_infos[] = {
F1("convert_uudecode", MAY_BE_STRING|MAY_BE_FALSE),
F1("var_export", MAY_BE_STRING|MAY_BE_NULL),
F1("serialize", MAY_BE_STRING),
F1("msg_stat_queue", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_FALSE),
F1("tidy_get_config", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING),
F1("token_get_all", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY),
F1("xml_error_string", MAY_BE_STRING|MAY_BE_NULL),
F1("xml_parser_get_option", MAY_BE_STRING|MAY_BE_LONG),
FN("zip_open", MAY_BE_RESOURCE|MAY_BE_LONG|MAY_BE_FALSE),
Expand All @@ -727,4 +730,9 @@ static const func_info_t func_infos[] = {
F1("gzinflate", MAY_BE_STRING|MAY_BE_FALSE),
F1("gzdecode", MAY_BE_STRING|MAY_BE_FALSE),
F1("gzuncompress", MAY_BE_STRING|MAY_BE_FALSE),
F1("apache_request_headers", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING),
F1("apache_get_modules", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
F1("fpm_get_status", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY|MAY_BE_FALSE),
F1("litespeed_response_headers", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
F1("phpdbg_get_executable", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ARRAY),
};
4 changes: 4 additions & 0 deletions ext/sysvmsg/sysvmsg.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ function msg_receive(

function msg_remove_queue(SysvMessageQueue $queue): bool {}

/**
* @return array<string, int>|false
* @refcount 1
*/
function msg_stat_queue(SysvMessageQueue $queue): array|false {}

function msg_set_queue(SysvMessageQueue $queue, array $data): bool {}
Expand Down
2 changes: 1 addition & 1 deletion ext/sysvmsg/sysvmsg_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 7acab08abf78d75df333fccd6c47266823a92103 */
* Stub hash: ea292758c1118e90b2c2e1f23883d107363d5801 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_msg_get_queue, 0, 1, SysvMessageQueue, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, key, IS_LONG, 0)
Expand Down
5 changes: 5 additions & 0 deletions ext/tidy/tidy.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function tidy_get_release(): string {}
function tidy_get_opt_doc(tidy $tidy, string $option): string|false {}
#endif

/**
* @return array<string, bool|int|string>
* @refcount 1
*/
function tidy_get_config(tidy $tidy): array {}

function tidy_get_status(tidy $tidy): int {}
Expand Down Expand Up @@ -99,6 +103,7 @@ public function diagnose(): bool {}
public function getRelease(): string {}

/**
* @return array<string, bool|int|string>
* @tentative-return-type
* @alias tidy_get_config
*/
Expand Down
2 changes: 1 addition & 1 deletion ext/tidy/tidy_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 4e5f6c0e7c6b8a6939a13276e3e68d2614a73d7e */
* Stub hash: fd1aedcfc9ff4fc6d0819e6b3502c05fb5234fc5 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_tidy_parse_string, 0, 1, tidy, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
Expand Down
4 changes: 4 additions & 0 deletions ext/tokenizer/tokenizer.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

/** @generate-class-entries */

/**
* @return array<int, array>
* @refcount 1
*/
function token_get_all(string $code, int $flags = 0): array {}

function token_name(int $id): string {}
Expand Down
2 changes: 1 addition & 1 deletion ext/tokenizer/tokenizer_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 60b4c809624eb4c1ef610e5c5820acfc87f6b07f */
* Stub hash: adba76b3f96e8da4a5ea2ff19ed5a61a3875002f */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_token_get_all, 0, 1, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, code, IS_STRING, 0)
Expand Down
17 changes: 16 additions & 1 deletion sapi/apache2handler/php_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ function apache_lookup_uri(string $filename): object|false {}

function virtual(string $uri): bool {}

/**
* @return array<string, string>
* @refcount 1
*/
function apache_request_headers(): array {}

/** @alias apache_request_headers */
/**
* @return array<string, string>
* @alias apache_request_headers
*/
function getallheaders(): array {}

/**
* @return array<string, string>
* @refcount 1
*/
function apache_response_headers(): array {}

function apache_note(string $note_name, ?string $note_value = null): string|false {}
Expand All @@ -21,4 +32,8 @@ function apache_getenv(string $variable, bool $walk_to_top = false): string|fals

function apache_get_version(): string|false {}

/**
* @return array<int, string>
* @refcount 1
*/
function apache_get_modules(): array {}
2 changes: 1 addition & 1 deletion sapi/apache2handler/php_functions_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 130666f6f971fe7b43a450d922e4b3d092e78667 */
* Stub hash: 0bedb66b9075e97871863e2700316f6448dfdcb2 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_apache_lookup_uri, 0, 1, MAY_BE_OBJECT|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
Expand Down
13 changes: 12 additions & 1 deletion sapi/cgi/cgi_main.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

function apache_child_terminate(): void {}

/**
* @return array<string, string>
* @refcount 1
*/
function apache_request_headers(): array {}

/** @alias apache_request_headers */
/**
* @return array<string, string>
* @alias apache_request_headers
*/
function getallheaders(): array {}

/**
* @return array<string, string>
* @refcount 1
*/
function apache_response_headers(): array {}
2 changes: 1 addition & 1 deletion sapi/cgi/cgi_main_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: df963adc6bc610cdd31861036889141fa9464ded */
* Stub hash: 0bb44f898b32fb2b83865432c081ad796ca2436a */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_apache_child_terminate, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
Expand Down
16 changes: 14 additions & 2 deletions sapi/cli/php_cli_server.stub.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
<?php

/**
* @return array<string, string>
* @refcount 1
*/
function apache_request_headers(): array {}

function apache_response_headers(): array {}

/**
* @return array<string, string>
* @alias apache_request_headers
*/
function getallheaders(): array {}

/**
* @return array<string, string>
* @refcount 1
*/
function apache_response_headers(): array {}
6 changes: 3 additions & 3 deletions sapi/cli/php_cli_server_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 60cd531d36a34fe7c51982e9ec40b45d2a2a4ce7 */
* Stub hash: 989efabf5eb29593017b16d62d41c7920760435d */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_apache_request_headers, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

#define arginfo_apache_response_headers arginfo_apache_request_headers

#define arginfo_getallheaders arginfo_apache_request_headers

#define arginfo_apache_response_headers arginfo_apache_request_headers
13 changes: 12 additions & 1 deletion sapi/fpm/fpm/fpm_main.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@

function fastcgi_finish_request(): bool {}

/**
* @return array<string, string>
* @refcount 1
*/
function apache_request_headers(): array {}

/** @alias apache_request_headers */
/**
* @return array<string, string>
* @alias apache_request_headers
*/
function getallheaders(): array {}

/**
* @return array<string, int|string|array>|false
* @refcount 1
*/
function fpm_get_status(): array|false {}
2 changes: 1 addition & 1 deletion sapi/fpm/fpm/fpm_main_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: b4ac4c0f1d91c354293e21185a2e6d9f99cc9fcc */
* Stub hash: b9e9164e2a07a33cc5c1efd6b710a505d64696cf */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_fastcgi_finish_request, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
Expand Down
2 changes: 1 addition & 1 deletion sapi/litespeed/lsapi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ static int add_associate_array( const char * pKey, int keyLen, const char * pVal


/* {{{ Fetch all HTTP request headers */
PHP_FUNCTION(litespeed_request_headers)
PHP_FUNCTION(apache_request_headers)
{
if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
Expand Down
27 changes: 24 additions & 3 deletions sapi/litespeed/lsapi_main.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,40 @@

/** @generate-class-entries */

/**
* @return array<string, string>
* @alias apache_request_headers
*/
function litespeed_request_headers(): array {}

/** @alias litespeed_request_headers */
/**
* @return array<string, string>
* @alias apache_request_headers
*/
function getallheaders(): array {}

/** @alias litespeed_request_headers */
/**
* @return array<string, string>
* @refcount 1
*/
function apache_request_headers(): array {}

/**
* @return array<string, string>|false
* @refcount 1
*/
function litespeed_response_headers(): array|false {}

/** @alias litespeed_response_headers */
/**
* @return array<string, string>|false
* @alias litespeed_response_headers
*/
function apache_response_headers(): array|false {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike other SAPIs, litespeed makes apache_request_headers() and apache_response_headers() an alias of its own implementations. The former one can be safely changed (so that litespeed_request_headers() becomes the alias of apache_request_headers()), however the latter one cannot, since the return type is different (array|false vs array). Can we somehow remove the false return? Or what could we do in order to add apache_response_headers() to the optimizer func info?


/**
* @return array<int, string>
* @refcount 1
*/
function apache_get_modules(): array {}

function litespeed_finish_request(): bool {}
10 changes: 5 additions & 5 deletions sapi/litespeed/lsapi_main_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 3419f4e77bd091e09e0cfc55d81f443d5a3396ff */
* Stub hash: c15e39addd40a6244694c37fecc88464fcf4db0d */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_litespeed_request_headers, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
Expand All @@ -19,16 +19,16 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_litespeed_finish_request, 0, 0,
ZEND_END_ARG_INFO()


ZEND_FUNCTION(litespeed_request_headers);
ZEND_FUNCTION(apache_request_headers);
ZEND_FUNCTION(litespeed_response_headers);
ZEND_FUNCTION(apache_get_modules);
ZEND_FUNCTION(litespeed_finish_request);


static const zend_function_entry ext_functions[] = {
ZEND_FE(litespeed_request_headers, arginfo_litespeed_request_headers)
ZEND_FALIAS(getallheaders, litespeed_request_headers, arginfo_getallheaders)
ZEND_FALIAS(apache_request_headers, litespeed_request_headers, arginfo_apache_request_headers)
ZEND_FALIAS(litespeed_request_headers, apache_request_headers, arginfo_litespeed_request_headers)
ZEND_FALIAS(getallheaders, apache_request_headers, arginfo_getallheaders)
ZEND_FE(apache_request_headers, arginfo_apache_request_headers)
ZEND_FE(litespeed_response_headers, arginfo_litespeed_response_headers)
ZEND_FALIAS(apache_response_headers, litespeed_response_headers, arginfo_apache_response_headers)
ZEND_FE(apache_get_modules, arginfo_apache_get_modules)
Expand Down
4 changes: 4 additions & 0 deletions sapi/phpdbg/phpdbg.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ function phpdbg_start_oplog(): void {}

function phpdbg_end_oplog(array $options = []): ?array {}

/**
* @return array<string, array>
* @refcount 1
*/
function phpdbg_get_executable(array $options = []): array {}
2 changes: 1 addition & 1 deletion sapi/phpdbg/phpdbg_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: dc2e5420ea396c6235429c9606875ad2332811cb */
* Stub hash: 18a28c3d2b1d3cc0f4afe3b173a6daa619fe9af1 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_phpdbg_break_next, 0, 0, IS_VOID, 0)
ZEND_END_ARG_INFO()
Expand Down