diff --git a/lib/private/cache/cappedmemorycache.php b/lib/private/cache/cappedmemorycache.php index cfaf78c51d..e3efbf76a2 100644 --- a/lib/private/cache/cappedmemorycache.php +++ b/lib/private/cache/cappedmemorycache.php @@ -64,8 +64,8 @@ class CappedMemoryCache implements ICache, \ArrayAccess { return $this->hasKey($offset); } - public function offsetGet($offset) { - return $this->get($offset); + public function &offsetGet($offset) { + return $this->cache[$offset]; } public function offsetSet($offset, $value) { diff --git a/tests/lib/cache/cappedmemorycache.php b/tests/lib/cache/cappedmemorycache.php index 5444d92842..a8fb273b80 100644 --- a/tests/lib/cache/cappedmemorycache.php +++ b/tests/lib/cache/cappedmemorycache.php @@ -64,4 +64,16 @@ class CappedMemoryCache extends \Test_Cache { $this->assertFalse($this->instance->hasKey('2_value1')); $this->assertFalse($this->instance->hasKey('3_value1')); } + + function testIndirectSet() { + $this->instance->set('array', []); + + $this->instance['array'][] = 'foo'; + + $this->assertEquals(['foo'], $this->instance->get('array')); + + $this->instance['array']['bar'] = 'qwerty'; + + $this->assertEquals(['foo', 'bar' => 'qwerty'], $this->instance->get('array')); + } }