php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55738 intval IP address
Submitted: 2011-09-20 10:02 UTC Modified: 2011-09-21 08:35 UTC
From: vlado107 at yahoo dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.8 OS: Win
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vlado107 at yahoo dot com
New email:
PHP Version: OS:

 

 [2011-09-20 10:02 UTC] vlado107 at yahoo dot com
Description:
------------
Problem in some cases when use intval($ip);


Test script:
---------------
$ip = '127.0.1.1';
echo $ip == intval($ip); // true

$ip = '127.1.1.1';
echo $ip == intval($ip); // false

Expected result:
----------------
Both result should be false


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-20 11:25 UTC] laruence@php.net
-Status: Open +Status: Bogus
 [2011-09-20 11:25 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

(number) 127.1.1.1  = 127.0
 [2011-09-20 11:27 UTC] laruence@php.net
sorry, typo.

(number) 127.1.1.1 = 127.1
 [2011-09-20 21:49 UTC] vlado107 at yahoo dot com
(number) 127.1.1.1 = 127.1
Yes, this is ok.
$ip = '127.1.1.1';
echo $ip == intval($ip); 
Ti is false and it should be false because 127.1.1.1 is not equal with 127.1

Problem is if IP is 127.0.1.1

$ip = '127.0.1.1';
echo $ip == intval($ip); // true

This is  127.0.1.1 == 127.0 and it is true. How it can be true? It should be 
false like in first case.
 [2011-09-21 08:35 UTC] laruence@php.net
(number)127.0.1.1 = (number) 127.0 = (int) 127
(number)127.1.1.1 = (number) 127.1 = (float) 127.1
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 09:01:32 2025 UTC