Skip to content

EloquentCollection->intersect misbehaves when called with null argument #30626

@jonaslm

Description

@jonaslm
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions