php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36967 ip2long returns unsigned long instead of signed long
Submitted: 2006-04-04 15:39 UTC Modified: 2006-04-04 16:36 UTC
From: php at cakkie dot be Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.2 OS: Linux Gentoo
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: php at cakkie dot be
New email:
PHP Version: OS:

 

 [2006-04-04 15:39 UTC] php at cakkie dot be
Description:
------------
I'm using the same code on 2 servers.

One server is a 2.6.6 debian with PHP 4.3.10
This one returns a signed long (as it should according to the documentation)

The other server is a 2.6.14 Gentoo with PHP 4.4.0
This one returns an unsigned long (not what it should be)

Since I didn't find any bugreport, nor other information regarding this behaviour, I decided to post a bug.

As a reference, I have an example, along with phpinfo() running at both servers:
correct: http://www.funpages.be/index.php
incorrect: http://www.factsoflife.be/cakkie/index.php


Reproduce code:
---------------
echo ip2long('217.136.232.103');

Expected result:
----------------
-645339033


Actual result:
--------------
3649628263

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-04 16:36 UTC] derick@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

It's actually correct as your 2nd machine is a 64bit machine, where PHP's integers are also 64bit. To make this portable, use sprintf("%u", ip2long(....));
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 11:00:02 2025 UTC