note 48239 added to function.serialize

From: Date: Thu, 16 Dec 2004 11:40:40 +0000
Subject: note 48239 added to function.serialize
Groups: php.notes 
Request: Send a blank email to php-notes+get-81854@lists.php.net to get a copy of this message
Warning: on 64 bits machines, if you use a long string only composed of numbers as a key in an array and serialize/unserialize it, you can run into problems: an example code: $arr["20041001103319"] = 'test'; var_dump( $arr); $arr_in_str = serialize($arr); print "Now result is: $arr_in_str<BR />"; $final_arr = unserialize($arr_in_str); print "The final unserialized array:<BR />"; var_dump($final_arr); The result: array(1) { [20041001103319]=> string(4) "test" } Now result is: a:1:{i:20041001103319;s:4:"test";} The final unserialized array: array(1) { [683700183]=> string(4) "test" } As you can see, the original array : $arr["20041001103319"] = "test" after serialize/unserialize is: $arr[683700183] = "test" As you can see, the key has changed ... Apparently a problem of implicit casting + integer overflow (I posted a PHP bug report: http://bugs.php.net/bug.php?id=31117) I tested with the latest 4.3.10 compiled on my laptop (32 bits, Mandrake 9.1) --> no such problem. But compiled on AMD 64 bits (Red Hat Taroon), the problem is present. Hope this will help some of you to not loose almost a whole day of debugging ;-) ---- Manual Page -- http://www.php.net/manual/en/function.serialize.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48239 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48239&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48239&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48239&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48239&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48239&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48239&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48239&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81854) next »