Serialization of double values in PHP 4 and PHP 5

If you want to save space in your serialized data of floating point numbers in PHP, consider to use PHP 4. Naturally that is a joke :), I just note it down here because while taking a closer look on the is_serialized() function again (#9930, #14429) I ran over a difference between PHP 4 and PHP 5.


A double value encoded in the PHP file as 1e99 which is in interpreted as float(1.0E+99) is serialized in PHP 4 as string(25) "d:1.0000000000000046E+99;" where as PHP 5 prefers string(102) "d:99999999999999996733...62608739868455469056;". Both unserialize back to float(1.0E+99). And both PHP versions can unserialize the value of the other version (with some differences on the value naturally as this is floating point which has limited precision and it does so as well when not switching PHP versions).

The whole is_serialized() topic got some traction lately after Rasmus Lerdorf threw strpbrk() onto it in some of his PHP Performance talks.

This entry was posted in Hacking The Core, Patched and tagged , , , , , , , , , , , , , , , . Bookmark the permalink.

1 Response to Serialization of double values in PHP 4 and PHP 5

  1. Pingback: PHP Serialize does References | hakre on wordpress

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.