From b48392f71435810bf6c8bc0faa440c9daa0a94a8 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 18 Aug 2026 07:30:35 +0200 Subject: [PATCH 1/3] ext/sockets: socket_cmsg_space() returns int, never null The nullable return type dates from the stub introduction, when the error paths were warnings followed by a bare return. PHP 8.0 turned them into ValueError, so every exit is now either RETURN_LONG or RETURN_THROWS. --- ext/sockets/sockets.stub.php | 2 +- ext/sockets/sockets_arginfo.h | 4 +- .../tests/socket_cmsg_space_return_type.phpt | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 ext/sockets/tests/socket_cmsg_space_return_type.phpt diff --git a/ext/sockets/sockets.stub.php b/ext/sockets/sockets.stub.php index 56b2ac07e868..fab32628544d 100644 --- a/ext/sockets/sockets.stub.php +++ b/ext/sockets/sockets.stub.php @@ -2313,7 +2313,7 @@ function socket_sendmsg(Socket $socket, array $message, int $flags = 0): int|fal function socket_recvmsg(Socket $socket, array &$message, int $flags = 0): int|false {} -function socket_cmsg_space(int $level, int $type, int $num = 0): ?int {} +function socket_cmsg_space(int $level, int $type, int $num = 0): int {} /** * @return array|false diff --git a/ext/sockets/sockets_arginfo.h b/ext/sockets/sockets_arginfo.h index 2592cb740865..cfd792244084 100644 --- a/ext/sockets/sockets_arginfo.h +++ b/ext/sockets/sockets_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit sockets.stub.php instead. - * Stub hash: 5e71ef16f2121bd6c75794673d0e0a394759ff8b */ + * Stub hash: 711d3b84051445917c4a8a1d0cdc1d0c6328be07 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_select, 0, 4, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(1, read, IS_ARRAY, 1) @@ -174,7 +174,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_recvmsg, 0, 2, MAY_BE_LON ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_socket_cmsg_space, 0, 2, IS_LONG, 1) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_socket_cmsg_space, 0, 2, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, num, IS_LONG, 0, "0") diff --git a/ext/sockets/tests/socket_cmsg_space_return_type.phpt b/ext/sockets/tests/socket_cmsg_space_return_type.phpt new file mode 100644 index 000000000000..4e24fd713a98 --- /dev/null +++ b/ext/sockets/tests/socket_cmsg_space_return_type.phpt @@ -0,0 +1,47 @@ +--TEST-- +socket_cmsg_space() always returns int, never null +--EXTENSIONS-- +sockets +--SKIPIF-- + +--FILE-- +getMessage(), "\n"; +} + +// Negative $num +try { + socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, -1); +} catch (ValueError $e) { + echo $e->getMessage(), "\n"; +} + +// $num overflows int (64-bit only: PHP_INT_MAX > INT_MAX) +if (PHP_INT_SIZE >= 8) { + try { + socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, PHP_INT_MAX); + } catch (ValueError $e) { + echo $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +string(3) "int" +Pair level 999999 and/or type 999999 is not supported +socket_cmsg_space(): Argument #3 ($num) must be greater than or equal to 0 +socket_cmsg_space(): Argument #3 ($num) must be between -2147483648 and 2147483647 From 4b04b6a353a5b1efbef82f3dc9c9e643533d518b Mon Sep 17 00:00:00 2001 From: Louis-Arnaud Date: Tue, 18 Aug 2026 16:26:51 +0200 Subject: [PATCH 2/3] Update socket_cmsg_space_return_type.phpt Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com> --- .../tests/socket_cmsg_space_return_type.phpt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/sockets/tests/socket_cmsg_space_return_type.phpt b/ext/sockets/tests/socket_cmsg_space_return_type.phpt index 4e24fd713a98..f8b0b7364611 100644 --- a/ext/sockets/tests/socket_cmsg_space_return_type.phpt +++ b/ext/sockets/tests/socket_cmsg_space_return_type.phpt @@ -20,28 +20,28 @@ var_dump(get_debug_type($r)); // Unknown level/type pair try { socket_cmsg_space(999999, 999999); -} catch (ValueError $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } // Negative $num try { socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, -1); -} catch (ValueError $e) { - echo $e->getMessage(), "\n"; +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } // $num overflows int (64-bit only: PHP_INT_MAX > INT_MAX) if (PHP_INT_SIZE >= 8) { try { socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, PHP_INT_MAX); - } catch (ValueError $e) { - echo $e->getMessage(), "\n"; + } catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } } ?> --EXPECT-- string(3) "int" -Pair level 999999 and/or type 999999 is not supported -socket_cmsg_space(): Argument #3 ($num) must be greater than or equal to 0 -socket_cmsg_space(): Argument #3 ($num) must be between -2147483648 and 2147483647 +ValueError: Pair level 999999 and/or type 999999 is not supported +ValueError: socket_cmsg_space(): Argument #3 ($num) must be greater than or equal to 0 +ValueError: socket_cmsg_space(): Argument #3 ($num) must be between -2147483648 and 2147483647 From 7a3f01c8d3c1a9c085b16a842575e890afe32f34 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Wed, 19 Aug 2026 07:29:54 +0200 Subject: [PATCH 3/3] Add UPGRADING entry for socket_cmsg_space() return type --- UPGRADING | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UPGRADING b/UPGRADING index e32c1fe55748..651d2af23c30 100644 --- a/UPGRADING +++ b/UPGRADING @@ -596,6 +596,9 @@ PHP 8.6 UPGRADE NOTES . socket_addrinfo_lookup() now has an additional optional argument $error when not null, and on failure, gives the error code (one of the EAI_* constants). + . socket_cmsg_space() return type has been narrowed from ?int to int. Every + failure path has thrown a ValueError since PHP 8.0, so null was never + returned. - Standard: . ini_get_all() now includes a "builtin_default_value" element for each