php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 + 16 = ?
Subscribe to this entry?

 
 [2012-08-24 17:46 UTC] rafagd at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.geoip-country-code-by-name
---

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:
---------------
<?php

$name = geoip_country_code_by_name("127.0.0.1");

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 127.0.0.1 not found in <b>/path/to/file.php</b> on line <b>3</b><br />
{ error : "Not Found" }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-24 17:47 UTC] ohill@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ohill
 [2012-08-24 17:47 UTC] ohill@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
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.

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

<?php
error_reporting(-1);
ini_set('display_errors', 0);
var_dump(geoip_country_code_by_name('154.106.91.217'));


PHP Notice:  geoip_country_code_by_name(): Host 154.106.91.217 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-2020 The PHP Group
All rights reserved.
Last updated: Sat Aug 08 01:01:25 2020 UTC