lionsoul2014/ip2region · error · Exception

invalid verstion name `{$ver_name}`

Error message

invalid verstion name `{$ver_name}`

What it means

PHP versionFromName sentinel: the uppercased name matches neither V4/IPV4 nor V6/IPV6, so no Version instance can be constructed from the given string.

Source

Thrown at binding/php/xdb/Searcher.class.php:77

        $r = strcmp($ip1, $ip2);
        if ($r < 0) {
            return -1;
        } else if ($r > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    // version parse
    public static function versionFromName($ver_name) {
        $name = strtoupper($ver_name);
        if ($name == "V4" || $name == "IPv4") {
            return IPv4::default();
        } else if ($name == "V6" || $name == "IPv6") {
            return IPv6::default();
        } else {
            throw new Exception("invalid verstion name `{$ver_name}`");
        }
    }

    // version parse from header
    public static function versionFromHeader($header) {
        // Old structure 2.0 with IPv4 supports ONLY
        if ($header['version'] == Structure_20) {
            return IPv4::default();
        }

        // structure 3.0 after IPv6 supporting
        if ($header['version'] != Structure_30) {
            throw new Exception("invalid xdb structure version `{$header['version']}`");
        }

        if ($header['ipVersion'] == IPv4VersionNo) {
            return IPv4::default();
        } else if ($header['ipVersion'] == IPv6VersionNo) {

View on GitHub (pinned to c1a1fc7d59)

Solutions

  1. Pass 'v4', 'ipv4', 'v6' or 'ipv6' (case-insensitive)
  2. Use versionFromHeader to derive the version from the xdb file itself
  3. Validate the config value against a whitelist before calling the searcher factory
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at binding/php/xdb/Searcher.class.php:77 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of lionsoul2014/ip2region@c1a1fc7d59 (2026-09-02). Data as JSON: /api/errors/b703a34aa1aa822c. Report an issue: GitHub.