Commit d3b58843e55 for php

commit d3b58843e55de8c925c67e3d09b63d12d71ed7d4
Author: lacatoire <la.catoire@gmail.com>
Date:   Thu Nov 5 15:57:52 2026 +0100

    ext/sockets: Fix socket_set_option() TypeError naming the wrong MCAST_* option

    The TypeError of socket_set_option() for a non-array $value always names
    MCAST_LEAVE_GROUP or MCAST_LEAVE_SOURCE_GROUP, even for MCAST_JOIN_GROUP,
    MCAST_BLOCK_SOURCE, MCAST_UNBLOCK_SOURCE and MCAST_JOIN_SOURCE_GROUP. The
    message now names the option given.

    Close GH-25892

diff --git a/NEWS b/NEWS
index 7a3f2087bd2..781825003b8 100644
--- a/NEWS
+++ b/NEWS
@@ -245,6 +245,8 @@ PHP                                                                        NEWS
   . Fixed host names being truncated at NUL bytes in socket_addrinfo_lookup(),
     socket_bind(), socket_connect(), socket_sendto() and socket_sendmsg().
     (Jorg Sowa)
+  . Fixed the TypeError of socket_set_option() naming the wrong option for
+    the MCAST_* multicast options. (lacatoire)

 - Session:
   . Fixed session upload progress to respect session.use_only_cookies.
diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c
index 6ccaf5fdf67..ed2afcebd75 100644
--- a/ext/sockets/multicast.c
+++ b/ext/sockets/multicast.c
@@ -142,6 +142,28 @@ static zend_result php_get_address_from_array(const HashTable *ht, const char *k
 	return SUCCESS;
 }

+static const char *php_mcast_option_name(int optname)
+{
+	switch (optname) {
+	case PHP_MCAST_JOIN_GROUP:
+		return "MCAST_JOIN_GROUP";
+	case PHP_MCAST_LEAVE_GROUP:
+		return "MCAST_LEAVE_GROUP";
+#ifdef HAS_MCAST_EXT
+	case PHP_MCAST_BLOCK_SOURCE:
+		return "MCAST_BLOCK_SOURCE";
+	case PHP_MCAST_UNBLOCK_SOURCE:
+		return "MCAST_UNBLOCK_SOURCE";
+	case PHP_MCAST_JOIN_SOURCE_GROUP:
+		return "MCAST_JOIN_SOURCE_GROUP";
+	case PHP_MCAST_LEAVE_SOURCE_GROUP:
+		return "MCAST_LEAVE_SOURCE_GROUP";
+#endif
+	default:
+		ZEND_UNREACHABLE();
+	}
+}
+
 static zend_result php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *arg4)
 {
 	HashTable		 		*opt_ht;
@@ -167,7 +189,7 @@ mcast_req_fun: ;

 			if (Z_TYPE_P(arg4) != IS_ARRAY) {
 				if (UNEXPECTED(Z_TYPE_P(arg4) != IS_OBJECT)) {
-					zend_argument_type_error(4, "must be of type array when argument #3 ($option) is MCAST_LEAVE_GROUP, %s given", zend_zval_value_name(arg4));
+					zend_argument_type_error(4, "must be of type array when argument #3 ($option) is %s, %s given", php_mcast_option_name(optname), zend_zval_value_name(arg4));
 					return FAILURE;
 				} else {
 					opt_ht = Z_OBJPROP_P(arg4);
@@ -210,7 +232,7 @@ mcast_req_fun: ;
 									slen;
 			if (Z_TYPE_P(arg4) != IS_ARRAY) {
 				if (UNEXPECTED(Z_TYPE_P(arg4) != IS_OBJECT)) {
-					zend_argument_type_error(4, "must be of type array when argument #3 ($option) is MCAST_LEAVE_SOURCE_GROUP, %s given", zend_zval_value_name(arg4));
+					zend_argument_type_error(4, "must be of type array when argument #3 ($option) is %s, %s given", php_mcast_option_name(optname), zend_zval_value_name(arg4));
 					return FAILURE;
 				} else {
 					opt_ht = Z_OBJPROP_P(arg4);
diff --git a/ext/sockets/tests/socket_set_option_mcast_error_names.phpt b/ext/sockets/tests/socket_set_option_mcast_error_names.phpt
new file mode 100644
index 00000000000..81d0c86675a
--- /dev/null
+++ b/ext/sockets/tests/socket_set_option_mcast_error_names.phpt
@@ -0,0 +1,32 @@
+--TEST--
+socket_set_option(): the TypeError of the MCAST_* options names the option given
+--EXTENSIONS--
+sockets
+--SKIPIF--
+<?php
+if (PHP_OS == 'Darwin') die('skip Not for macOS');
+?>
+--FILE--
+<?php
+
+$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+
+foreach (['MCAST_JOIN_GROUP', 'MCAST_LEAVE_GROUP', 'MCAST_BLOCK_SOURCE', 'MCAST_UNBLOCK_SOURCE', 'MCAST_JOIN_SOURCE_GROUP', 'MCAST_LEAVE_SOURCE_GROUP'] as $name) {
+    if (!defined($name)) {
+        continue;
+    }
+    try {
+        socket_set_option($socket, IPPROTO_IP, constant($name), 1);
+    } catch (TypeError $e) {
+        echo $e->getMessage(), "\n";
+    }
+}
+
+?>
+--EXPECT--
+socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_JOIN_GROUP, int given
+socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_GROUP, int given
+socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_BLOCK_SOURCE, int given
+socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_UNBLOCK_SOURCE, int given
+socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_JOIN_SOURCE_GROUP, int given
+socket_set_option(): Argument #4 ($value) must be of type array when argument #3 ($option) is MCAST_LEAVE_SOURCE_GROUP, int given