|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34553 gethostbynamel() returns wrong type
Submitted: 2005-09-19 21:39 UTC Modified: 2005-09-19 22:32 UTC
From: webdev at concraption dot com Assigned:
Status: Not a bug Package: *Network Functions
PHP Version: 5.0.5 OS: Windows 2000/XP
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:
Solve the problem:
45 + 40 = ?
Subscribe to this entry?

 [2005-09-19 21:39 UTC] webdev at concraption dot com
The online documentation for gethostbynamel() states that if the lookup fails, it will return FALSE. The Win32 binary of PHP 5.0.5 returns what appears to be an empty string, rather than FALSE on the case of failed lookup. If this is an error in the documentation, I apologize for your time.

I was able to devise a workaround using is_array() in an IF block, but out of curiousity I added die(">".$hosts."<"); and PHP returned ><, which leads me to believe that when the lookup fails, $hosts is an empty string rather than FALSE.

Reproduce code:
$hosts = gethostbynamel($hostname);
if ($hosts != FALSE) {
     echo $hostname." is tied to the following IPs:<br><br>";
     foreach ($hosts as $ip) {
          echo "IP: ".$ip."<br>";
} else {
     echo $hostname." is not tied to any IP.";

Expected result:
$hostname is tied to the following IPs:

IP: first_ip
IP: second_ip



$hostname is not tied to any IP.

Actual result:
Warning: Invalid argument supplied for foreach() in C:\Server\sites\apps\iptools.php on line 12


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-19 21:44 UTC]
what do you get with this:

 [2005-09-19 22:03 UTC] webdev at concraption dot com
string(0) ""
 [2005-09-19 22:25 UTC]
Your code doesn't really depend on what the return value is, as ("" == false) in PHP. So if you get the error you get, $hosts is neither empty string, nor false. 
And I can't reproduce it, btw.
So please come up with the real code.
 [2005-09-19 22:29 UTC] webdev at concraption dot com
I reinstalled PHP and now var_dump returns bool(false), so it must've been something with that installation. Thanks for your help.
 [2005-09-19 22:32 UTC]
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jun 24 19:07:23 2021 UTC