diff --git a/src/Illuminate/Cache/ArrayStore.php b/src/Illuminate/Cache/ArrayStore.php index cf95fe31a900..f1f00d637be9 100644 --- a/src/Illuminate/Cache/ArrayStore.php +++ b/src/Illuminate/Cache/ArrayStore.php @@ -110,9 +110,13 @@ public function forever($key, $value) */ public function forget($key) { - unset($this->storage[$key]); + if (array_key_exists($key, $this->storage)) { + unset($this->storage[$key]); - return true; + return true; + } + + return false; } /** diff --git a/tests/Cache/CacheArrayStoreTest.php b/tests/Cache/CacheArrayStoreTest.php index 09303f01238d..6259f5cb5e43 100755 --- a/tests/Cache/CacheArrayStoreTest.php +++ b/tests/Cache/CacheArrayStoreTest.php @@ -87,8 +87,9 @@ public function testItemsCanBeRemoved() { $store = new ArrayStore; $store->put('foo', 'bar', 10); - $store->forget('foo'); + $this->assertTrue($store->forget('foo')); $this->assertNull($store->get('foo')); + $this->assertFalse($store->forget('foo')); } public function testItemsCanBeFlushed()