note 48556 deleted from function.unserialize by nlopess

From: Date: Wed, 29 Dec 2004 13:59:01 +0000
Subject: note 48556 deleted from function.unserialize by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-82457@lists.php.net to get a copy of this message
Note Submitter: wiart at yahoo dot com ---- 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" } 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 ;-)

« previous php.notes (#82457) next »