php.net |  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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: webdev at concraption dot com
New email:
PHP Version: OS:

 

 [2005-09-19 21:39 UTC] webdev at concraption dot com
Description:
------------
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

etc...

OR

$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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-19 21:44 UTC] tony2001@php.net
what do you get with this:
<?php
...
var_dump(gethostbynamel($hostname));
...
?>

?
 [2005-09-19 22:03 UTC] webdev at concraption dot com
string(0) ""
 [2005-09-19 22:25 UTC] tony2001@php.net
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] tony2001@php.net
.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 12:01:23 2019 UTC