From 26f4a8b88ab6e314071faa48f53694c7a8a08609 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Thu, 19 Oct 2017 12:30:05 +0200 Subject: [PATCH 1/3] Let Arr::wrap(null) return empty array --- src/Illuminate/Support/Arr.php | 4 ++++ tests/Support/SupportArrTest.php | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index a9e09ce81287..e49fc1b8d5c1 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -601,6 +601,10 @@ public static function where($array, callable $callback) */ public static function wrap($value) { + if ($value === null) { + return []; + } + return ! is_array($value) ? [$value] : $value; } } diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 794e9de2e46a..90644d9a5474 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -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)); } } From d2894fa7cac3ac855a9a8b22dc01214644ee8774 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Thu, 19 Oct 2017 14:10:20 +0200 Subject: [PATCH 2/3] Fix comment --- src/Illuminate/Support/Arr.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index e49fc1b8d5c1..54bc6670052f 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -594,7 +594,7 @@ 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. Return an empty array if the value is null. * * @param mixed $value * @return array From a6e5c200cf7ea0fb72b90c22f2f5db4a2dee7633 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 19 Oct 2017 07:43:38 -0500 Subject: [PATCH 3/3] Update Arr.php --- src/Illuminate/Support/Arr.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index 54bc6670052f..df9f8a142eee 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -594,14 +594,14 @@ public static function where($array, callable $callback) } /** - * If the given value is not an array and not null, wrap it in one. Return an empty array if the value is null. + * 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 ($value === null) { + if (is_null($value)) { return []; }