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