Skip to content

Commit 5703943

Browse files
viestnikic
authored andcommitted
Deprecate AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES
These flags have been deprecated in glibc 2.28, so we also deprecate them in PHP. As we can't deprecate constants, we can only check for their use in socket_addrinfo_lookup().
1 parent 774cdb1 commit 5703943

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ PHP 7.4 UPGRADE NOTES
404404
// $str = ReflectionClass::export(Foo::class, true) is:
405405
$str = (string) new ReflectionClass(Foo::class);
406406

407+
- Socket:
408+
. The AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES flags for
409+
socket_addrinfo_lookup() are deprecated, due to an upstream deprecation in
410+
glibc.
411+
407412
- Standard:
408413
. Passing invalid characters to ''base_convert()'', ''bindec()'', ''octdec()''
409414
and ''hexdec()'' will now generate a deprecation notice. The result will

ext/sockets/sockets.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,14 @@ PHP_FUNCTION(socket_addrinfo_lookup)
25732573
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zhints), key, hint) {
25742574
if (key) {
25752575
if (zend_string_equals_literal(key, "ai_flags")) {
2576-
hints.ai_flags = zval_get_long(hint);
2576+
zend_long flags = zval_get_long(hint);
2577+
#if HAVE_AI_IDN
2578+
if (flags & (AI_IDN_ALLOW_UNASSIGNED | AI_IDN_USE_STD3_ASCII_RULES)) {
2579+
php_error_docref(NULL, E_DEPRECATED,
2580+
"AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES are deprecated");
2581+
}
2582+
#endif
2583+
hints.ai_flags = flags;
25772584
} else if (zend_string_equals_literal(key, "ai_socktype")) {
25782585
hints.ai_socktype = zval_get_long(hint);
25792586
} else if (zend_string_equals_literal(key, "ai_protocol")) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES are deprecated
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('sockets')) die('skip The sockets extension is not loaded');
6+
if (!defined('AI_IDN_ALLOW_UNASSIGNED')) die('skip AI_IDN_ALLOW_UNASSIGNED not defined');
7+
?>
8+
--FILE--
9+
<?php
10+
$addrinfo = socket_addrinfo_lookup('127.0.0.1', 2000, array(
11+
'ai_family' => AF_INET,
12+
'ai_socktype' => SOCK_DGRAM,
13+
'ai_flags' => AI_IDN_ALLOW_UNASSIGNED,
14+
));
15+
var_dump(socket_addrinfo_connect($addrinfo[0]));
16+
echo "Done";
17+
--EXPECTF--
18+
Deprecated: socket_addrinfo_lookup(): AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES are deprecated in %s on line %d
19+
resource(%d) of type (Socket)
20+
Done

0 commit comments

Comments
 (0)