Skip to content

Commit e3546de

Browse files
authored
Make collect() helper consistent with new Collection() (#45401)
Even though using `null` and `[]` as argument produce the same result, syntactically they are different as PHPStan is unable to infer template types when `null` is passed. Currently when using `collect()` PHPStan will report these errors (as seen in larastan issue larastan/larastan#1115): ``` Unable to resolve the template type TKey in call to function collect Unable to resolve the template type TValue in call to function collect ``` As a workaround you either have to explicitly pass empty array `collect([])` or use `new Collection()`. I'm not sure if this is considered breaking BC or not. I tried searching for existing issue/PR regarding this, but couldn't find anything. I apologize if this was addressed and declined already.
1 parent 81c7bee commit e3546de

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Illuminate/Collections/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue>|null $value
1414
* @return \Illuminate\Support\Collection<TKey, TValue>
1515
*/
16-
function collect($value = null)
16+
function collect($value = [])
1717
{
1818
return new Collection($value);
1919
}

0 commit comments

Comments
 (0)