Framework: EloquentCollection->intersect misbehaves when called with null argument

Created on 19 Nov 2019  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 6.5.1
  • PHP Version: 7.3
  • Database Driver & Version: N/A

Description:

When calling $collection->intersect(null) on an Eloquent Collection the whole $collection is returned. I would expect an error or, possibly, an empty collection to be returned. Note that doing the same thing on a regular base collection returns an empty collection.

We had this happen, causing silent errors (we called intersect with a nonexistant relation as argument, which gets returned as null).

Steps To Reproduce:

Assuming you have an Eloquent Collection $eloquentCollection that isn't empty, simply call

$eloquentCollection->intersect(null);

The entire collection will be returned. Expected behavior would be an error or, possibly, an empty collection. Again, note that doing the same thing on a base collection returns an empty collection.

bug

All 3 comments

Tested this and confirmed. This indeed seems like unwanted behavior. Welcoming prs for this.

@ahinkle this bug only occurs on Eloquent collection

Was this page helpful?
0 / 5 - 0 ratings

Related issues

progmars picture progmars  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments