php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44317 crc32() function breaks compatibility on 32-bit and 64-bit platforms
Submitted: 2008-03-03 09:42 UTC Modified: 2008-03-03 14:12 UTC
From: vadim at vadiaz dot com Assigned: pajoye (profile)
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.5 OS: Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vadim at vadiaz dot com
New email:
PHP Version: OS:

 

 [2008-03-03 09:42 UTC] vadim at vadiaz dot com
Description:
------------
crc32() function result differs on 32-bit and 64-bit platforms which break compatibility.
there is very ugly workaround like using dechex(crc32()) but this means that all the code must be reviewed before migrating to any platform which is not 32bit.
Even there is no unsigned integer in PHP, this function must return the same numeric result. And sure this buggy behavior must be well documented.


Reproduce code:
---------------
php -r ' echo crc32("platform independant") . "\n";'

Expected result:
----------------
-858128794

Actual result:
--------------
3436838502

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-03 14:12 UTC] pajoye@php.net
As you noticed PHP has no unsigned integer. It can't return the same visual result without using strings. But we can't return string as it will break the backward compatibility and will add other bad side effects (related to bc too). See the manual notes if you like to get ride of this limitation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 22:01:29 2024 UTC