Skip to content

Commit

Permalink
revert breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 17, 2018
1 parent 3f42299 commit 6197e56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public function forget($keys)
*/
public function get($key, $default = null)
{
return Arr::get($this->items, $key, $default);
return is_null($key) ? null : Arr::get($this->items, $key, $default);

This comment has been minimized.

Copy link
@vlakoff

vlakoff Jan 17, 2018

Contributor

Should probably return value($default) rather than null. See previous version in #22554.

And tests should be added for custom default values (see SupportCollectionTest.php below).

}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,12 @@ public function testGetNestedValue()
$this->assertEquals('Book 1', $collection->get('foo.books.0'));
$this->assertEquals('Todo 2', $collection->get('foo.todos.second'));
}

public function testGetWithNullReturnsNull()
{
$collection = new Collection([1, 2, 3]);
$this->assertNull($collection->get(null));
}
}

class TestSupportCollectionHigherOrderItem
Expand Down

1 comment on commit 6197e56

@vlakoff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, Arr::get($array, null) returns the whole array.

Please sign in to comment.