Commit a183f1162e2 for php.net

commit a183f1162e231739e8877dff2de65f51efaeba0f
Author: Louis-Arnaud <la.catoire@gmail.com>
Date:   Wed Aug 19 14:22:25 2026 +0200

    ext/sockets: socket_cmsg_space() returns int, never null (#23345)

    * 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.

    Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com>

diff --git a/UPGRADING b/UPGRADING
index d6e24356ee3..350d30b1263 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -604,6 +604,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
diff --git a/ext/sockets/sockets.stub.php b/ext/sockets/sockets.stub.php
index 56b2ac07e86..fab32628544 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<int, AddressInfo>|false
diff --git a/ext/sockets/sockets_arginfo.h b/ext/sockets/sockets_arginfo.h
index 2592cb74086..cfd79224408 100644
Binary files a/ext/sockets/sockets_arginfo.h and b/ext/sockets/sockets_arginfo.h differ
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 00000000000..f8b0b736461
--- /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--
+<?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