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
 [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: Fri Mar 29 10:01:28 2024 UTC