|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62926 Unnecessary E_NOTICE thrown when geoip_country_code_by_name can't find IP.
Submitted: 2012-08-24 17:46 UTC Modified: 2012-08-24 18:30 UTC
From: rafagd at gmail dot com Assigned: ohill (profile)
Status: Closed Package: geoip (PECL)
PHP Version: 5.4.6 OS: Debian Gnu/Linux (wheezy)
Private report: No CVE-ID: None
 [2012-08-24 17:46 UTC] rafagd at gmail dot com
From manual page:

On development environment, with E_NOTICE enabled, this function will throw an uncatchable and undocumented notice if it can't find the ip, which might break layouts or protocols.

=== Suggestion ===

Remove the notice, the function already inform you it couldn't find the IP by returning false.

=== Workaround ===

Add @ before the function name, disabling any error messages it might throw.

Test script:

$name = geoip_country_code_by_name("");

header("Content-type: application/json");

if ($name) {
    echo json_encode(array( "name"  => $name ));
} else {
    echo json_encode(array( "error"  => "Not Found" ));


Expected result:
A json-encoded response like this:
{ error : "Not Found" }

Actual result:
<b>Notice</b>:  geoip_country_code_by_name(): Host not found in <b>/path/to/file.php</b> on line <b>3</b><br />
{ error : "Not Found" }


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-24 17:47 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: ohill
 [2012-08-24 17:47 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.
 [2012-08-24 17:57 UTC] rafagd at gmail dot com
Woah, that was fast.

 [2012-08-24 18:30 UTC]
Actually it has been like that on SVN for some time now. It will be in the next 
 [2014-12-01 09:39 UTC] nikita dot arykov at gmail dot com
Bug still reproduced for this source code

ini_set('display_errors', 0);

PHP Notice:  geoip_country_code_by_name(): Host not found in /root/t.php on line 4
 [2014-12-01 09:40 UTC] nikita dot arykov at gmail dot com
php -v
PHP 5.4.17 (cli) (built: Oct  2 2013 16:18:19)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 03:01:24 2021 UTC