Skip to content

Commit 189751c

Browse files
committed
Promote notice to ValueError for invalid hint key
1 parent 2a71cb3 commit 189751c

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

ext/sockets/sockets.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,8 +2315,9 @@ PHP_FUNCTION(socket_addrinfo_lookup)
23152315
} else if (zend_string_equals_literal(key, "ai_family")) {
23162316
hints.ai_family = zval_get_long(hint);
23172317
} else {
2318-
/* TODO Promote to warning/error? */
2319-
php_error_docref(NULL, E_NOTICE, "Unknown hint %s", ZSTR_VAL(key));
2318+
zend_argument_value_error(3, "must only contain array keys \"ai_flags\", \"ai_socktype\", "
2319+
"\"ai_protocol\", or \"ai_family\"");
2320+
RETURN_THROWS();
23202321
}
23212322
}
23222323
} ZEND_HASH_FOREACH_END();

ext/sockets/tests/socket_addrinfo_lookup.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ if (!extension_loaded('sockets')) {
77
}
88
--FILE--
99
<?php
10-
$addrinfo = socket_addrinfo_lookup('127.0.0.1', 2000, array(
11-
'ai_family' => AF_INET,
12-
'ai_socktype' => SOCK_DGRAM,
13-
'invalid' => null,
14-
));
15-
var_dump($addrinfo[0]);
16-
echo "Done";
17-
?>
18-
--EXPECTF--
19-
Notice: socket_addrinfo_lookup(): Unknown hint invalid in %ssocket_addrinfo_lookup.php on line %d
20-
object(AddressInfo)#%d (0) {
10+
try {
11+
$addrinfo = socket_addrinfo_lookup('127.0.0.1', 2000, array(
12+
'ai_family' => AF_INET,
13+
'ai_socktype' => SOCK_DGRAM,
14+
'invalid' => null,
15+
));
16+
var_dump($addrinfo[0]);
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage(), \PHP_EOL;
2119
}
22-
Done
20+
?>
21+
--EXPECT--
22+
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)