{"record":{"id":"d342f2aaf650bbfc","repo":"lionsoul2014/ip2region","slug":"invalid-ip-address-ip-d342f2","errorCode":null,"errorMessage":"invalid ip address `{$ip}`","messagePattern":"invalid ip address `(.+?)`","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"binding/php/xdb/Searcher.class.php","lineNumber":469,"sourceCode":"    public function getIPVersion() {\n        return $this->version;\n    }\n\n    public function getIOCount() {\n        return $this->ioCount;\n    }\n\n    /**\n     * find the region info for the specified ip address.\n     * @Note: the ip address couldO ONLY be a human-readable IP address string,\n     * DO not use the packed binary string returned by #parseIP\n     * \n     * @throws Exception\n     */\n    public function search($ip) {\n        $ipBytes = Util::parseIP($ip);\n        if ($ipBytes == null) {\n            throw new Exception(\"invalid ip address `{$ip}`\");\n        }\n\n        return $this->searchByBytes($ipBytes);\n    }\n\n    /**\n     * find the region info for the specified binary ip bytes returned by #parseIP.\n     * \n     * @throws Exception\n     */\n    public function searchByBytes($ipBytes) {\n        // ip version check\n        if (strlen($ipBytes) != $this->version->bytes) {\n            throw new Exception(\"invalid ip address ({$this->version->name} expected)\");\n        }\n\n        // reset the global counter\n        $this->ioCount = 0;","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/php/xdb/Searcher.class.php#L451-L487","documentation":"Defensive guard in the PHP searcher: Util::parseIP returned null for the input, meaning the string could not be parsed as either IPv4 or IPv6. Note the util parser normally throws on bad syntax, so hitting this null check indicates a parse failure path that yielded null rather than an exception.","triggerScenarios":"Thrown at binding/php/xdb/Searcher.class.php:469 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a valid human-readable IPv4 or IPv6 string (not the packed binary from Util::parseIP)","Pre-validate with filter_var($ip, FILTER_VALIDATE_IP) before searching","Route the query to a searcher whose version matches the address family"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}