At the moment caching is only serialized for arrays and objects. There for the dataype e.g. 'integer' and 'double' are lost when retrieving a variable.
This fix sets all datatypes that are not a string serialized so this data is preserved.

Tests for this bug are provided here:
http://drupal.org/node/276267

CommentFileSizeAuthor
fix_cache_datatype.patch616 bytesR.Muilwijk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

Priority: Critical » Normal
Status: Needs review » Reviewed & tested by the community

Well. PHP is a loosely typed language, after all, so I can't see how this could be a problem. At least, that's not critical.

However, the patch looks good and promote consistency, so marking as RTBC.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

Please write some tests for this. It is important when people write an alternative cache backend. They could re-use these tests. Thanks!

R.Muilwijk’s picture

Status: Needs work » Reviewed & tested by the community

@Dries, as said in the topic the tests are already written on: http://drupal.org/node/276267

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Good catch.

Anonymous’s picture

Is it possible that cache_set could be storing a resource id? If so then we need to also filter !is_resource($data) because you cannot serialize a resource. Actually, I'm not sure we shouldn't also serialize the strings. So I think we should instead do

-  if (is_object($data) || is_array($data)) {
+  if (!is_resource($data)) {
cwgordon7’s picture

Let the resources get serialized.

Anonymous’s picture

From http://us2.php.net/manual/en/function.serialize.php we see serialize() handles all types, except the resource-type.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.