Undefined Index In ObjectHydrator #6116

Closed
opened 2026-01-22 15:26:59 +01:00 by admin · 8 comments
Owner

Originally created by @kiler129 on GitHub (Dec 1, 2018).

Bug Report

Q A
BC Break yes/no
Version doctrine/orm v2.6.3

Summary

ObjectHydrator crashes during iterate(). I wasn't able to write a failing test case as discussed with @Ocramius on Slack.

How to reproduce

https://github.com/kiler129/doctrine_undef_idx/blob/master/src/Command/TestCommand.php

This is a minimal project which will crash doctrine: https://github.com/kiler129/doctrine_undef_idx
Also failing testcase is available: https://github.com/doctrine/doctrine2/pull/7499

Expected behavior

The objects are hydrated properly.

Note

There's a horrible, hacky, and dangerous way to walk around the issue which should never be used (unless you have few days to a major release):

$q = $qb->getQuery();

$qi = $q->iterate();
$qiRef = new \ReflectionObject($qi);
$hpref = $qiRef->getProperty('_hydrator');
$hpref->setAccessible(true);
$hydrator = $hpref->getValue($qi);
$href = new \ReflectionObject($hydrator);
$qiRC = $href->getProperty('identifierMap');
$qiRC->setAccessible(true);

foreach ($qi as $x) {
  //.....

  $qiRC->setValue($hydrator, []);
}
Originally created by @kiler129 on GitHub (Dec 1, 2018). ### Bug Report | Q | A |------------ | ------ | BC Break | yes/no | Version | `doctrine/orm` v2.6.3 #### Summary `ObjectHydrator` crashes during `iterate()`. ~I wasn't able to write a failing test case as discussed with @Ocramius on Slack.~ #### How to reproduce https://github.com/kiler129/doctrine_undef_idx/blob/master/src/Command/TestCommand.php This is a minimal project which will crash doctrine: https://github.com/kiler129/doctrine_undef_idx Also failing testcase is available: https://github.com/doctrine/doctrine2/pull/7499 #### Expected behavior The objects are hydrated properly. #### Note There's a horrible, hacky, and dangerous way to walk around the issue which should never be used (unless you have few days to a major release): ```php $q = $qb->getQuery(); $qi = $q->iterate(); $qiRef = new \ReflectionObject($qi); $hpref = $qiRef->getProperty('_hydrator'); $hpref->setAccessible(true); $hydrator = $hpref->getValue($qi); $href = new \ReflectionObject($hydrator); $qiRC = $href->getProperty('identifierMap'); $qiRC->setAccessible(true); foreach ($qi as $x) { //..... $qiRC->setValue($hydrator, []); } ```
admin closed this issue 2026-01-22 15:27:00 +01:00
Author
Owner

@kiler129 commented on GitHub (Dec 1, 2018):

It may be related to:

@kiler129 commented on GitHub (Dec 1, 2018): It may be related to: - https://github.com/doctrine/doctrine2/issues/3238 - https://github.com/doctrine/doctrine2/issues/4071
Author
Owner

@Ocramius commented on GitHub (Dec 1, 2018):

Can you please represent the same test in the form of a unit test, like in https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket

@Ocramius commented on GitHub (Dec 1, 2018): Can you please represent the same test in the form of a unit test, like in https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM/Functional/Ticket
Author
Owner

@Ocramius commented on GitHub (Dec 1, 2018):

Sorry, closed by accident due to mobile UI.

@Ocramius commented on GitHub (Dec 1, 2018): Sorry, closed by accident due to mobile UI.
Author
Owner

@kiler129 commented on GitHub (Dec 1, 2018):

I fiddled with this and I think I created the simplest scenario possible in a form of a functional testcase: https://github.com/doctrine/doctrine2/pull/7499

@kiler129 commented on GitHub (Dec 1, 2018): I fiddled with this and I think I created the simplest scenario possible in a form of a functional testcase: https://github.com/doctrine/doctrine2/pull/7499
Author
Owner

@peter-gribanov commented on GitHub (Feb 1, 2019):

I encountered the same problem.

My code:

public function iterate(): iterable
{
    foreach ($this->rep->createQueryBuilder('e')->getQuery()->iterate() as $row) {
        yield current($row);
    }
}

Error:

In ObjectHydrator.php line 525:

  [Symfony\Component\Debug\Exception\ContextErrorException]
  Notice: Undefined offset: 318

Exception trace:
 () at /application/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:525
 Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData() at /application/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:177
 Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateRow() at /application/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php:81

In ObjectHydrator#L525 the $result variable equals empty array.

$ composer show --latest 'doctrine/*'
doctrine/annotations                v1.6.0  v1.6.0  Docblock Annotations Parser
doctrine/cache                      v1.8.0  v1.8.0  Caching library offering an object-oriented API for many cache backends
doctrine/collections                v1.5.0  v1.5.0  Collections Abstraction library
doctrine/common                     v2.10.0 v2.10.0 PHP Doctrine Common project is a library that provides additional functionality that other Doctrine p...
doctrine/dbal                       v2.9.0  v2.9.2  Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection a...
doctrine/doctrine-bundle            1.10.0  1.10.1  Symfony DoctrineBundle
doctrine/doctrine-cache-bundle      1.3.5   1.3.5   Symfony Bundle for Doctrine Cache
doctrine/doctrine-migrations-bundle v1.3.2  v2.0.0  Symfony DoctrineMigrationsBundle
doctrine/event-manager              v1.0.0  v1.0.0  Doctrine Event Manager component
doctrine/inflector                  v1.3.0  v1.3.0  Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator               1.1.0   1.1.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                      v1.0.1  v1.0.1  Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                 v1.8.1  v2.0.0  Database Schema migrations using Doctrine DBAL
doctrine/orm                        v2.6.3  v2.6.3  Object-Relational-Mapper for PHP
doctrine/persistence                v1.1.0  v1.1.0  The Doctrine Persistence project is a set of shared interfaces and functionality that the different D...
doctrine/reflection                 v1.0.0  v1.0.0  Doctrine Reflection component
@peter-gribanov commented on GitHub (Feb 1, 2019): I encountered the same problem. My code: ```php public function iterate(): iterable { foreach ($this->rep->createQueryBuilder('e')->getQuery()->iterate() as $row) { yield current($row); } } ``` Error: ``` In ObjectHydrator.php line 525: [Symfony\Component\Debug\Exception\ContextErrorException] Notice: Undefined offset: 318 Exception trace: () at /application/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:525 Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateRowData() at /application/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:177 Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateRow() at /application/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/IterableResult.php:81 ``` In [ObjectHydrator#L525](https://github.com/doctrine/orm/blob/2.6/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php#L525) the `$result` variable equals empty array. ``` $ composer show --latest 'doctrine/*' doctrine/annotations v1.6.0 v1.6.0 Docblock Annotations Parser doctrine/cache v1.8.0 v1.8.0 Caching library offering an object-oriented API for many cache backends doctrine/collections v1.5.0 v1.5.0 Collections Abstraction library doctrine/common v2.10.0 v2.10.0 PHP Doctrine Common project is a library that provides additional functionality that other Doctrine p... doctrine/dbal v2.9.0 v2.9.2 Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection a... doctrine/doctrine-bundle 1.10.0 1.10.1 Symfony DoctrineBundle doctrine/doctrine-cache-bundle 1.3.5 1.3.5 Symfony Bundle for Doctrine Cache doctrine/doctrine-migrations-bundle v1.3.2 v2.0.0 Symfony DoctrineMigrationsBundle doctrine/event-manager v1.0.0 v1.0.0 Doctrine Event Manager component doctrine/inflector v1.3.0 v1.3.0 Common String Manipulations with regard to casing and singular/plural rules. doctrine/instantiator 1.1.0 1.1.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer v1.0.1 v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers. doctrine/migrations v1.8.1 v2.0.0 Database Schema migrations using Doctrine DBAL doctrine/orm v2.6.3 v2.6.3 Object-Relational-Mapper for PHP doctrine/persistence v1.1.0 v1.1.0 The Doctrine Persistence project is a set of shared interfaces and functionality that the different D... doctrine/reflection v1.0.0 v1.0.0 Doctrine Reflection component ```
Author
Owner

@peter-gribanov commented on GitHub (Mar 20, 2019):

Are there any updates for this?

@peter-gribanov commented on GitHub (Mar 20, 2019): Are there any updates for this?
Author
Owner

@SenseException commented on GitHub (Mar 21, 2019):

There's an open change request in #7499 that needs to be done.

@SenseException commented on GitHub (Mar 21, 2019): There's an open change request in #7499 that needs to be done.
Author
Owner

@beberlei commented on GitHub (Feb 8, 2021):

Bug is fixed with new AbstractQuery::toIterable and a fix in upcoming 2.8.2

@beberlei commented on GitHub (Feb 8, 2021): Bug is fixed with new `AbstractQuery::toIterable` and a fix in upcoming 2.8.2
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6116