|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59753 Host not found notice
Submitted: 2011-05-06 09:15 UTC Modified: 2011-05-06 12:51 UTC
From: visseraj at gmail dot com Assigned:
Status: Not a bug Package: geoip (PECL)
PHP Version: 5.3.2 OS: CentOS 5.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: visseraj at gmail dot com
New email:
PHP Version: OS:


 [2011-05-06 09:15 UTC] visseraj at gmail dot com
If you change the error_reporting php.ini setting to show notices, an unknown IP will cause geoip_record_by_name() to throw a notice that the host could not be found, in addition to returning false.  The documentation says it will just return false, so it would be nice to remove the notice, as that becomes annoying to deal with.

Reproduce code:


$geo = geoip_record_by_name('');


Expected result:
boolean false

Actual result:
Notice: geoip_record_by_name() [function.geoip-record-by-name]: Host not found in test.php

boolean false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-06 12:12 UTC]
Thank you for taking the time to write to us, but this is not
a bug.

I will check the documentation and update accordingly.

This is the expected behavior.
 [2011-05-06 12:25 UTC] visseraj at gmail dot com
I would like to propose a different solution.  Since notices 
more for undefined variables, etc. It would be better to 
throw an 
exception that could be caught and dealt wit. Yes,  
geoip_record_by_name() does return false, but there is 
you can do about the notice.


try {
   $geo = geoip_record_by_name('');
} catch (Exception $e) {
   $geo = // some default array

 [2011-05-06 12:34 UTC]
GeoIP is procedural and not OO style.

You can always run PHP without NOTICES (production recommended) or append a @ in front of the function.

The fact that is not in the DB is actual maybe a problem, as the GeoIP DB contains all "valid" IP. You might be passing an invalid IP, hence the NOTICE to help you debug.
 [2011-05-06 12:51 UTC] visseraj at gmail dot com
Please see this talk by Rasmus Lerdorf as to why I'm trying to get rid of the notice, 
that GeoIP is throwing.

I appreciate that you are trying to help people debug, but that fact of the matter is, 
that if GeoIP returns false instead of an array, when you go to try use the returned 
array, your code will fail because it isn't an array.  That is why I feel like the 
notice is unnecessary and harder to deal with, when you have notices turned on in dev. is an internal development IP, so that is why it isn't in the DB. But even 
if you get the latest MaxMind DB there might still be missing IPs.

Putting a @ in front of GeoIP is extremely bad practice so I refused to do that.
 [2011-05-22 13:26 UTC] radek at pinkbike dot com
Placing @ in front of the function will suppress the 
reporting of "real" errors due to a db missing or the module 
not loaded. This is not the right solution.

We have the same pain with geoip throwing that notice in 
this situation.  It returns false if IP not found so it's a 
clear and consistent process to check for this situation on 
the user side.
I second that it should NOT throw a notice on ip not found.

This is the _only_ function in our whole system that needs 
special treatment because of this notice behaviour.
 [2012-02-02 09:41 UTC] jay-php at vengefulstapler dot com
One more vote for not having this throw a notice. Error suppression is bad for the 
reasons others have stated, and in development mode we have all errors set to 
display, to force developers to fix them. Well, our internal IP addresses are of 
course not found.
 [2015-05-01 20:41 UTC] krifa23 at gmail dot com
3 years have passed and still no solution to this bad practice? I agree with the guys that the function should throw an exception and not a notice.
 [2018-07-13 19:05 UTC] uriel dot rn at gmail dot com
Null returns at php7.2
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Jan 29 06:01:24 2020 UTC