yiisoft/yii2 · error · yii\base\NotSupportedException

IPv6 is not supported by inet_pton()!

Error message

IPv6 is not supported by inet_pton()!

What it means

IpHelper::ip2bin() converts addresses to a bit string; for IPv6 it relies on inet_pton(). The method first probes @inet_pton('::1') and, if that probe fails, throws yii\base\NotSupportedException — meaning the running PHP build's inet_pton() cannot process IPv6 at all. It is a platform capability check, not an input validation failure.

Source

Thrown at framework/helpers/BaseIpHelper.php:115

    {
        $hex = unpack('H*hex', inet_pton($ip));
        return substr(preg_replace('/([a-f0-9]{4})/i', '$1:', $hex['hex']), 0, -1);
    }

    /**
     * Converts IP address to bits representation.
     *
     * @param string $ip the valid IPv4 or IPv6 address
     * @return string bits as a string
     * @throws NotSupportedException
     */
    public static function ip2bin($ip)
    {
        $ipBinary = null;
        if (static::getIpVersion($ip) === self::IPV4) {
            $ipBinary = pack('N', ip2long($ip));
        } elseif (@inet_pton('::1') === false) {
            throw new NotSupportedException('IPv6 is not supported by inet_pton()!');
        } else {
            $ipBinary = inet_pton($ip);
        }

        $result = '';
        for ($i = 0, $iMax = strlen($ipBinary); $i < $iMax; $i += 4) {
            $result .= str_pad(decbin(unpack('N', substr($ipBinary, $i, 4))[1]), 32, '0', STR_PAD_LEFT);
        }
        return $result;
    }
}

View on GitHub (pinned to 66f00d18a2)

Solutions

  1. Upgrade PHP to a build with full IPv6 inet_pton support; verify with var_dump(@inet_pton('::1')); — it must not be false.
  2. Add a startup capability check so the app fails fast with a clear message on incompatible hosts.
  3. Catch NotSupportedException at the IP-processing boundary, log the address family, and skip features that need bit-level IPv6.
  4. If upgrading is impossible, route IPv6 handling through a pure-PHP 128-bit encoder instead of inet_pton().

Example fix

// before
$bits = IpHelper::ip2bin($ip); // $ip = '2001:db8::1' on a broken build

// after
if (@inet_pton('::1') === false) {
    throw new \RuntimeException('This PHP build cannot process IPv6 addresses');
}
$bits = IpHelper::ip2bin($ip);
Defensive patterns

Strategy: validation

Validate before calling

if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && @inet_pton('::1') === false) {
    throw new \RuntimeException('This platform cannot process IPv6 addresses');
}
$bits = \yii\helpers\IpHelper::ip2bin($ip);

Try / catch

try {
    $bits = \yii\helpers\IpHelper::ip2bin($ip);
} catch (\yii\base\NotSupportedException $e) {
    \Yii::error('IPv6 processing unavailable on this host: ' . $ip, 'network');
    throw $e;
}

Prevention

When it happens

Trigger: IpHelper::ip2bin('2001:db8::1') on a PHP compiled against a C library with IPv6-disabled inet_pton (seen on legacy Windows builds and some embedded stacks); IPv6 CIDR checks via IpHelper::inRange() or ip2bin-based comparisons that only receive IPv6 input behind dual-stack load balancers.

Common situations: Apps deployed to old Windows/IIS servers or unusual containers where IPv6 support was not compiled in; production-only failures because only prod traffic includes IPv6 clients; local dev on outdated XAMPP/WAMP builds passing all tests while the IPv6 path is never exercised.

Related errors


AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17). Data as JSON: /api/errors/cf8c4ef82e55afae. Report an issue: GitHub.