PHP Warning \Doctrine\ORM\QueryBuilder::where #7327

Closed
opened 2026-01-22 15:50:00 +01:00 by admin · 1 comment
Owner

Originally created by @mmross on GitHub (Feb 16, 2024).

Bug Report (PHP Warning)

Q A
BC Break no
Version 3.0.0

Summary

After upgrading to doctrine/orm 3.0.0 we found PHP Warnings.
PHP Warning: Undefined array key 0 in /var/www/html/vendor/doctrine/orm/src/QueryBuilder.php on line 954

Current behavior

$qb = $this->getEntityManager()->createQueryBuilder();
        $qb
            ->delete(delete: Foo::class, alias: 'foo')
            ->where(predicates: $qb->expr()->lt('foo.creationDate', ':creationDate'));

Inside of the where method

if (! (count($predicates) === 1 && $predicates[0] instanceof Expr\Composite)) {
            $predicates = new Expr\Andx($predicates);
        }

the value of $predicates is in this example an array like this

array(1) {
  ["predicates"]=>
  object(Doctrine\ORM\Query\Expr\Comparison)#921 (3) {
    ["leftExpr":protected]=>
    string(14) "ael.occurredAt"
    ["operator":protected]=>
    string(1) "<"
    ["rightExpr":protected]=>
    string(11) ":occurredAt"
  }
}

And this logic will throw the php warning.

Expected behavior

No PHP Warnings
It would be better to check that this value is an array and that key exists with the php method array_key_exists.

I can prepare a solution for this if I don't overlook anything about using the where method.

Originally created by @mmross on GitHub (Feb 16, 2024). ### Bug Report (PHP Warning) | Q | A |------------ | ------ | BC Break | no | Version | 3.0.0 #### Summary After upgrading to doctrine/orm 3.0.0 we found PHP Warnings. _PHP Warning: Undefined array key 0 in /var/www/html/vendor/doctrine/orm/src/QueryBuilder.php on line 954_ #### Current behavior ``` $qb = $this->getEntityManager()->createQueryBuilder(); $qb ->delete(delete: Foo::class, alias: 'foo') ->where(predicates: $qb->expr()->lt('foo.creationDate', ':creationDate')); ``` Inside of the where method ``` if (! (count($predicates) === 1 && $predicates[0] instanceof Expr\Composite)) { $predicates = new Expr\Andx($predicates); } ``` the value of $predicates is in this example an array like this ``` array(1) { ["predicates"]=> object(Doctrine\ORM\Query\Expr\Comparison)#921 (3) { ["leftExpr":protected]=> string(14) "ael.occurredAt" ["operator":protected]=> string(1) "<" ["rightExpr":protected]=> string(11) ":occurredAt" } } ``` And this logic will throw the php warning. #### Expected behavior No PHP Warnings It would be better to check that this value is an array and that key exists with the php method array_key_exists. I can prepare a solution for this if I don't overlook anything about using the where method.
admin closed this issue 2026-01-22 15:50:00 +01:00
Author
Owner

@derrabus commented on GitHub (Feb 16, 2024):

Duplicate of #11253

@derrabus commented on GitHub (Feb 16, 2024): Duplicate of #11253
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7327