has a malformed IPv6 address, closing square bracket missing
Description
SNMP::__construct() accepts an IPv6 $hostname wrapped in square brackets, such as [::1] or [::1]:1161 for a non-default port. The closing ] is what tells the parser where the address ends and an optional :port suffix begins.
If the hostname starts with [ but never contains a matching ], the address cannot be parsed. As of PHP 8.6, this now throws a ValueError instead of emitting a warning and leaving the session half-constructed.
Example
<?php
$snmp = new SNMP(SNMP::VERSION_2c, '[::1', 'public');
?>
Literal Examples
- SNMP::__construct(): Argument #2 ($hostname) has a malformed IPv6 address, closing square bracket missing
Alternatives
- Make sure a bracketed IPv6
$hostnameis properly closed, e.g.[::1]or[::1]:1161.
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See [Previously, this emitted an E_WARNING (“Malformed IPv6 address, closing square bracket missing”) and left the SNMP object without a usable session, instead of throwing.](Previously, this emitted an E_WARNING (“Malformed IPv6 address, closing square bracket missing”) and left the SNMP object without a usable session, instead of throwing.)