|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 20:00:01 2025 UTC |
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);