From 42f21b95e892bd9c597496619ba4dcfc5d01e76b Mon Sep 17 00:00:00 2001 From: Thomas Ruiz Date: Fri, 1 Apr 2016 22:18:00 +0200 Subject: [PATCH] Fix Arr::get($array, null) when $array is empty --- src/Illuminate/Support/Arr.php | 2 +- tests/Support/SupportArrTest.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index 3759b04b8c2f..456b867f026c 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -262,7 +262,7 @@ public static function forget(&$array, $keys) */ public static function get($array, $key, $default = null) { - if (! $array) { + if (! static::accessible($array)) { return value($default); } diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 8651076e76e9..3b37d761f534 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -182,8 +182,13 @@ public function testGet() $this->assertNull(Arr::get($array, 'bar.baz', 'default')); // Test $array not an array - $this->assertEquals('default', Arr::get(null, 'foo', 'default')); - $this->assertEquals('default', Arr::get(false, 'foo', 'default')); + $this->assertSame('default', Arr::get(null, 'foo', 'default')); + $this->assertSame('default', Arr::get(false, 'foo', 'default')); + $this->assertSame('default', Arr::get(null, null, 'default')); + + // Test $array is empty and key is null + $this->assertSame([], Arr::get([], null)); + $this->assertSame([], Arr::get([], null, 'default')); } public function testHas()