if ($this->perfdebug) {
cache_helper::record_cache_hit('** static persist **', $this->definition->get_id());
}
+ if (!is_scalar($result)) {
+ // If data is an object it will be a reference.
+ // If data is an array if may contain references.
+ // We want to break references so that the cache cannot be modified outside of itself.
+ // Call the function to unreference it (in the best way possible).
+ $result = $this->unref($result);
+ }
return $result;
} else if ($this->perfdebug) {
cache_helper::record_cache_miss('** static persist **', $this->definition->get_id());
if ($setaftervalidation) {
$this->set($key, $result);
}
+ // 7. Make sure we don't pass back anything that could be a reference.
+ // We don't want people modifying the data in the cache.
+ if (!is_scalar($result)) {
+ // If data is an object it will be a reference.
+ // If data is an array if may contain references.
+ // We want to break references so that the cache cannot be modified outside of itself.
+ // Call the function to unreference it (in the best way possible).
+ $result = $this->unref($result);
+ }
return $result;
}
foreach ($keyvaluearray as $key => $value) {
if (is_object($value) && $value instanceof cacheable_object) {
$value = new cache_cached_object($value);
+ } else if (!is_scalar($value)) {
+ // If data is an object it will be a reference.
+ // If data is an array if may contain references.
+ // We want to break references so that the cache cannot be modified outside of itself.
+ // Call the function to unreference it (in the best way possible).
+ $value = $this->unref($value);
}
if ($simulatettl) {
$value = new cache_ttl_wrapper($value, $this->definition->get_ttl());
$var = $cache->get('obj');
$this->assertInstanceOf('stdClass', $var);
$this->assertEquals('value', $var->key);
+
+ // Reference test after retrieve.
+ $obj = new stdClass;
+ $obj->key = 'value';
+ $this->assertTrue($cache->set('obj', $obj));
+
+ $var1 = $cache->get('obj');
+ $this->assertInstanceOf('stdClass', $var1);
+ $this->assertEquals('value', $var1->key);
+ $var1->key = 'eulav';
+ $this->assertEquals('eulav', $var1->key);
+
+ $var2 = $cache->get('obj');
+ $this->assertInstanceOf('stdClass', $var2);
+ $this->assertEquals('value', $var2->key);
+
+ $this->assertTrue($cache->delete('obj'));
}
/**