When working with Field Collection, I encountered a bug #1084268: Exception: Invalid field name given. in FieldCollectionItemEntity. After reading the issue, this seemed to be caused by a bug in PHP 5.2.12 which has be resolved. But I'm using PHP 5.3.3(-1ubuntu9.5), so it should been fixed.

I'm using a SQLite database and from the backtrace I found the cause of the bug to be in DatabaseStatementPrefetch::current (DatabaseStatement_sqlite extends DatabaseStatementPrefetch). When the fetch mode is PDO::FETCH_CLASS, DatabaseStatementPrefetch::current create a new instance using a ReflectionClass and set its property from the fetched associative array.

This doesn't replicate the PDO behavior which is to set the properties of the new instance before executing its _construct method. This should either be changed to replicate the PDO behavior, or the documentation for DatabaseStatementInterface should clearly document it.

Comments

pbuyle’s picture

I would like to work on a patch for this but I would need some guidance. Should I work on Drupal 7 or 8 and then backport it to 7?

To fix this issue, I see two options:

  • User ReflectionClass::getConstructor to get the class constructor is a RelfectionMethod and then use ReflectionMethod::invokeArgs. But it will probably not work as I doubt it will change the class of the object passed as first argument.
  • Change the DatabaseStatementPrefetch::execute to use PDO::FETCH_CLASS to (pre-)fetch the data. But (pre-)creating all the instances on execute (and stroring them in DatabaseStatementPrefetch::$data) will prevent them from being garbage collected before the statement is.
pbuyle’s picture

Title: DatabaseStatementPrefetch doesn't set instance property before calling _construct » DatabaseStatementPrefetch doesn't set instance properties before calling _construct when using PDO::FETCH_CLASS
catch’s picture

Version: 7.7 » 8.x-dev
Issue tags: +Needs backport to D7

It does need an 8.x patch first, but a single patch should apply to both versions.

tim.plunkett’s picture

alaa’s picture

subscribing

sachbearbeiter’s picture

sub

leup’s picture

subscribe

Damien Tournoud’s picture

I think only the #2 option of #1 is valid. There is no way to create an object before calling the constructor without resorted to some ugly hacks (I also think I remember that more recent versions of PHP have a way to do that cleanly).

tim.plunkett’s picture

Priority: Major » Normal

The original issue for this bug had a workaround committed, and this issue has stagnated.
@mongolito404, are you still going to work on this?

pbuyle’s picture

@tim.plunkett I lack time to properly start working on patch(es) for Drupal 8 so I cannot commit to work on this issue. Sorry.

pbuyle’s picture

Issue summary: View changes

Fix a typo

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

daffie’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)