Skip to content
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
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/sockets/sockets.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, AddressInfo>|false
Expand Down
4 changes: 2 additions & 2 deletions ext/sockets/sockets_arginfo.h

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

47 changes: 47 additions & 0 deletions ext/sockets/tests/socket_cmsg_space_return_type.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--
socket_cmsg_space() always returns int, never null
--EXTENSIONS--
sockets
--SKIPIF--
<?php
if (PHP_OS_FAMILY === 'Windows') {
die('skip SCM_RIGHTS not available on Windows');
}
if (!defined('SCM_RIGHTS')) {
die('skip SCM_RIGHTS not defined on this platform');
}
?>
--FILE--
<?php
// Happy path: returns int, never null
$r = socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, 1);
var_dump(get_debug_type($r));

// Unknown level/type pair
try {
socket_cmsg_space(999999, 999999);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

// Negative $num
try {
socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, -1);
} 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 (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}
?>
--EXPECT--
string(3) "int"
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
Loading