Visite Webhosting Latino, el site sobre alojamiento web.
#29705 : ip2long returns false instead of -1 for "" - Mombu the Php Forum
Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #29705 : ip2long returns false instead of -1 for ""
User Name
REGISTER NOW! Mark Forums Read

sponsored links

1 31st July 10:56
External User
Posts: 1
Default #29705 : ip2long returns false instead of -1 for ""

ID: 29705
Updated by:
Reported By: andrew at is dot co dot za
-Status: Closed
+Status: Assigned
-Bug Type: Do***entation problem
+Bug Type: Feature/Change Request
Operating System: FreeBSD 4.6.2-RELEASE-p23
PHP Version: 5.0.0
-Assigned To:
+Assigned To: derick
New Comment:

I agree with that, but:
The inet_addr() function converts the Internet host address
cp from
numbers-and-dots notation into binary data in network byte
order. If
the input is invalid, INADDR_NONE (usually -1) is returned.
This is an
obsolete interface to inet_aton, described immediately above;
it is
obsolete because -1 is a valid address (, and
provides a cleaner way to indicate error return.

If I find some time I will implement it to use inet_aton if it is
supported on the platform. This will "break" BC again though...

Previous Comments:

[2004-08-16 15:15:17]

This bug has been fixed in the do***entation's XML sources. Since the
online and downloadable versions of the do***entation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our do***entation

"ip2long() will return -1 (PHP 4) or false (PHP 5) for the IP

But is valid address so this function should return
rather 4294967295 (-1 signed) for it IMHO.


[2004-08-16 14:36:18]

This is correct, it changed from 4.x to 5.0.0 (read the release

This should be fixed in the do***entation though.


[2004-08-16 13:14:02] andrew at is dot co dot za

ip2long has been changed to return "false" instead of -1 in the event
of a failure, presumably to fix the historical problem of not being
able to pass it "", which is a valid broadcast address
that evaluates to -1 when converted.

However, ip2long now returns "false" instead of -1 for
"", which contradicts the PHP do***entation.

Reproduce code:
if (ip2long("") === false) {
echo "Bad";
} else {
echo "OK";

Expected result:
Displays "Bad"

Actual result:
Should display "OK"


Edit this bug report at
  Reply With Quote

  sponsored links


Thread Tools
Display Modes

Copyright 2006 - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -