php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: visseraj at gmail dot com
New email:
PHP Version: OS:

 

 [2011-05-06 09:15 UTC] visseraj at gmail dot com
Description:
------------
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:
---------------
<?php

error_reporting(E_ALL);

$geo = geoip_record_by_name('10.10.10.10');

var_dump($geo);



Expected result:
----------------
boolean false

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

boolean false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-06 12:12 UTC] ohill@php.net
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 
are 
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 
nothing 
you can do about the notice.

<?php
error_reporting(E_ALL);

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

var_dump($geo);
 [2011-05-06 12:34 UTC] ohill@php.net
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 10.10.10.10 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. http://talks.php.net/show/phpcon2011/4


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.

10.10.10.10 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
 [2020-07-11 07:04 UTC] noahbin0829 at gmail dot com
Hi,friend.
My problem is: There is a mess code when I use this method to get the city name.
The result I want: Reykjavík,
but it gave me this result: Reykjav�k,
and I try to use the method mb_convert_encoding() or iconv(), but it still doesn't work.I don't think it's a charset problem.
So can you help me see what the problem is, thank you.
 [2020-07-11 07:04 UTC] noahbin0829 at gmail dot com
Hi,friend.
My problem is: There is a mess code when I use this method to get the city name.
The result I want: Reykjavík,
but it gave me this result: Reykjav�k,
and I try to use the method mb_convert_encoding() or iconv(), but it still doesn't work.I don't think it's a charset problem.
So can you help me see what the problem is, thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC