2008-05-27

PHP 在 32bit & 64bit 平台的差異

這個問題是在做一個系統轉換機器時發現的(從 i386 -> amd64)

主要是 Integer 在 32bit & 64bit 環境下位數表現的問題,我是在 dechex() 這個 function 踩到地雷 跟,不過其實應該只會在超過 65536 的整數才會出事(32bit unsigned),以下是 PHP 官方站相關參考

http://tw2.php.net/manual/en/function.dechex.php

To force the correct usage of 32-bit unsigned integer in some functions, just add '+0' just before processing them.

for example
echo(dechex("2724838310"));
will print '7FFFFFFF'
but it should print 'A269BBA6'

When adding '+0' php will handle the 32bit unsigned integer
correctly
echo(dechex("2724838310"+0));
will print 'A269BBA6'

沒有留言: