php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71100 long2ip() doesn't accept integers in strict mode
Submitted: 2015-12-12 06:21 UTC Modified: 2015-12-13 05:32 UTC
From: anthonyryan1 at gmail dot com Assigned: laruence (profile)
Status: Closed Package: *Network Functions
PHP Version: 7.0.0 OS: Linux
Private report: No CVE-ID: None
 [2015-12-12 06:21 UTC] anthonyryan1 at gmail dot com
Description:
------------
long2ip()'s expected input type does not match up with the output type of ip2long(), in strict mode passing an integer causes a TypeError to be thrown.

Test script:
---------------
<?php
declare(strict_types=1);

var_dump(long2ip(ip2long('127.0.0.1')));

Expected result:
----------------
long2ip()'s expected input type to be an integer in strict mode.

Actual result:
--------------
PHP Fatal error:  Uncaught TypeError: long2ip() expects parameter 1 to be string, integer given in test-script.php:4
Stack trace:
#0 test-script.php(4): long2ip(2130706433)
#1 {main}
  thrown in test-script.php on line 4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-12 06:35 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2015-12-12 06:35 UTC] laruence@php.net
That is why it cause "strict_types"

from doc:

string long2ip ( string $proper_address )

and 

int ip2long ( string $ip_address )

it's better we change long2ip accept long instead of string.

anyway, this is a little similar with #71053, I will also considered this case 

thanks
 [2015-12-13 05:32 UTC] laruence@php.net
-Status: Assigned +Status: Wont fix
 [2015-12-13 05:32 UTC] laruence@php.net
hmm, changing long2ip accept integer instead of string will break something in non strict_types like:
long2ip("");

thus I will only fixed this in master
 [2015-12-13 18:14 UTC] anthonyryan1 at gmail dot com
I see your point. What is the next PHP version this change could be considered for?

Based on what you're saying, am I correct in understanding a pull request fixing this would be accepted into master for a future (major) PHP release?
 [2015-12-14 06:55 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9b148d31d3e19ce8c726ebbab3ba6a9a24979a2f
Log: Fixed bug #71100 (long2ip() doesn't accept integers in strict mode)
 [2015-12-14 06:55 UTC] laruence@php.net
-Status: Wont fix +Status: Closed
 [2016-04-18 09:30 UTC] bwoebi@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9b148d31d3e19ce8c726ebbab3ba6a9a24979a2f
Log: Fixed bug #71100 (long2ip() doesn't accept integers in strict mode)
 [2016-07-20 11:34 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9b148d31d3e19ce8c726ebbab3ba6a9a24979a2f
Log: Fixed bug #71100 (long2ip() doesn't accept integers in strict mode)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC