Skip to content

Commit

Permalink
Merge pull request #12975 from thomasruiz/fix_arr_get
Browse files Browse the repository at this point in the history
[5.2] Fix Arr::get($array, null) when $array is empty
  • Loading branch information
taylorotwell committed Apr 2, 2016
2 parents cb5423c + 42f21b9 commit 3a46589
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 7 additions & 2 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3a46589

Please sign in to comment.