Skip to content

Commit a062021

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: ext/sockets: Accept an empty packed hints array in socket_addrinfo_lookup()
2 parents d68cd18 + f955aee commit a062021

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎ext/sockets/sockets.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2825,7 +2825,7 @@ PHP_FUNCTION(socket_addrinfo_lookup)
28252825
# endif
28262826
#endif
28272827

2828-
if (zhints) {
2828+
if (zhints && zend_hash_num_elements(Z_ARRVAL_P(zhints)) > 0) {
28292829
if (UNEXPECTED(HT_IS_PACKED(Z_ARRVAL_P(zhints)))) {
28302830
zend_argument_value_error(3, "must only contain array keys \"ai_flags\", \"ai_socktype\", "
28312831
"\"ai_protocol\", or \"ai_family\"");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
socket_addrinfo_lookup(): an empty packed hints array is accepted like []
3+
--EXTENSIONS--
4+
sockets
5+
--FILE--
6+
<?php
7+
$hints = [1];
8+
unset($hints[0]);
9+
var_dump(count($hints), $hints === []);
10+
var_dump(count(socket_addrinfo_lookup('127.0.0.1', '80', $hints)) === count(socket_addrinfo_lookup('127.0.0.1', '80', [])));
11+
try {
12+
socket_addrinfo_lookup('127.0.0.1', '80', [1]);
13+
} catch (Throwable $e) {
14+
echo $e::class, ': ', $e->getMessage(), "\n";
15+
}
16+
?>
17+
--EXPECT--
18+
int(0)
19+
bool(true)
20+
bool(true)
21+
ValueError: socket_addrinfo_lookup(): Argument #3 ($hints) must only contain array keys "ai_flags", "ai_socktype", "ai_protocol", or "ai_family"

0 commit comments

Comments
 (0)