Skip to content

Commit

Permalink
[5.6] Let Arr::wrap(null) return empty array (#21745)
Browse files Browse the repository at this point in the history
* Let Arr::wrap(null) return empty array

* Fix comment

* Update Arr.php
  • Loading branch information
TheAlexLichter authored and taylorotwell committed Oct 19, 2017
1 parent ad2374b commit b345fdf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,17 @@ public static function where($array, callable $callback)
}

/**
* If the given value is not an array, wrap it in one.
* If the given value is not an array and not null, wrap it in one.
*
* @param mixed $value
* @return array
*/
public static function wrap($value)
{
if (is_null($value)) {
return [];
}

return ! is_array($value) ? [$value] : $value;
}
}
1 change: 1 addition & 0 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,5 +662,6 @@ public function testWrap()
$this->assertEquals(['a'], Arr::wrap($string));
$this->assertEquals($array, Arr::wrap($array));
$this->assertEquals([$object], Arr::wrap($object));
$this->assertEquals([], Arr::wrap(null));
}
}

0 comments on commit b345fdf

Please sign in to comment.