php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39062 crc32() returns 64-bit number on 64-bit achitectures
Submitted: 2006-10-06 13:09 UTC Modified: 2006-10-06 15:11 UTC
From: ivoras at yahoo dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.1.6 OS: FreeBSD
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ivoras at yahoo dot com
New email:
PHP Version: OS:

 

 [2006-10-06 13:09 UTC] ivoras at yahoo dot com
Description:
------------
crc32() in PHP returns an integer larger than 2G on a 64-bit platform; It's documented, and applications rely on it, that it will return a signed integer from the range [-2G .. 2G]. The major problem with 64-bit crc32() here is that databases can't store the value in a column declared as INTEGER, thus braking compatibility.

Reproduce code:
---------------
echo crc32('10780');

Expected result:
----------------
-1171594808

Actual result:
--------------
3123372488

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-06 13:36 UTC] tony2001@php.net
Use dechex(crc32('10780')) to get string value, which is the same on all architectures.
The integer value differs because of obvious reasons.
 [2006-10-06 15:11 UTC] ivoras at yahoo dot com
I guess there's no way PHP will be ready for serious work with this kind of attitude. Type 'int' in C is signed 32-bit on all POSIX systems, and there had to be special work done to break the behaviour of a purely numeric integer function like crc32(). If you realise the brokeness, please update documentation, add a bug description section, wich at least documents it. The same suggestion is valid for all functions that substantially differ from documented behaviour on different architectures.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 22:01:28 2024 UTC