Skip to content

[5.5] WhereHas method blows up on PHP 7.3 when explicitly specifying an operator #25192

@CyberiaResurrection

Description

@CyberiaResurrection
  • Laravel Version: 5.5.42
  • PHP Version: 7.3.0beta1
  • Database Driver & Version: SQLite 3.24.0-1

Description:

Running a whereHas method off a hasMany relation blows up with:
ErrorException: compact(): Undefined variable: operator in file /var/www/testproject/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php on line 1243

Steps To Reproduce:

  1. Define a hasMany relation on a model. Ensure that the child model on the relation has at least one relation other than to the parent.
  2. Query the parent's hasMany relation - here's how I tripped over it:
$result = $parentModel->manyRelation()->whereHas('childOtherRelation', function ($query) use ($value) {
    $query->where('name', '=', $value);
})->firstOrFail();
  1. Execute that query under PHP 7.3. I tripped over this by running a test case.
  2. Bombs out with above error.

Looking at the chunk of code (addWhereExistsQuery in Query/Builder.php), I'm not seeing where $operator ever got defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions