From 0aba3305b3505bb8f66c12a0810ebd0c471cc7a2 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 17 Nov 2008 21:01:12 +0000 Subject: [PATCH] Use clone to break object refs when setting and getting cache. see #8146 #8191 git-svn-id: https://develop.svn.wordpress.org/trunk@9740 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/cache.php | 8 +++++++- wp-includes/functions.php | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/wp-includes/cache.php b/wp-includes/cache.php index a96be515dd..5eef60b13c 100644 --- a/wp-includes/cache.php +++ b/wp-includes/cache.php @@ -313,7 +313,10 @@ class WP_Object_Cache { if (isset ($this->cache[$group][$id])) { $this->cache_hits += 1; - return $this->cache[$group][$id]; + if ( is_object($this->cache[$group][$id]) ) + return wp_clone($this->cache[$group][$id]); + else + return $this->cache[$group][$id]; } if ( isset ($this->non_existant_objects[$group][$id]) ) @@ -373,6 +376,9 @@ class WP_Object_Cache { if (NULL === $data) $data = ''; + if ( is_object($data) ) + $data = wp_clone($data); + $this->cache[$group][$id] = $data; if(isset($this->non_existant_objects[$group][$id])) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 0368b09cde..da927ffcfe 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -2872,4 +2872,9 @@ function wp_suspend_cache_invalidation($suspend = true) { return $current_suspend; } +function wp_clone($object) { + return version_compare(phpversion(), '5.0') < 0 ? $object : clone($object); +} + + ?>