php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29705 ip2long returns false instead of -1 for "255.255.255.255"
Submitted: 2004-08-16 13:14 UTC Modified: 2004-11-01 10:41 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: andrew at is dot co dot za Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.0 OS: FreeBSD 4.6.2-RELEASE-p23
Private report: No CVE-ID: None
 [2004-08-16 13:14 UTC] andrew at is dot co dot za
Description:
------------
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 "255.255.255.255", which is a valid broadcast address that evaluates to -1 when converted.

However, ip2long now returns "false" instead of -1 for "255.255.255.255", which contradicts the PHP documentation.

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


Expected result:
----------------
Displays "Bad"

Actual result:
--------------
Should display "OK"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-16 14:36 UTC] derick@php.net
This is correct, it changed from 4.x to 5.0.0 (read the release notes).

This should be fixed in the documentation though.
 [2004-08-16 15:15 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation 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 documentation better.

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

But 255.255.255.255 is valid address so this function should return rather 4294967295 (-1 signed) for it IMHO.
 [2004-08-16 15:22 UTC] derick@php.net
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 (255.255.255.255), and inet_aton
       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...


 [2004-11-01 10:41 UTC] derick@php.net
This was already done on August 19th 2004, by Antony in revision 1.685.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 22:01:32 2024 UTC