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
Comment #1
pbuyle commentedI 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:
ReflectionClass::getConstructorto get the class constructor is aRelfectionMethodand then useReflectionMethod::invokeArgs. But it will probably not work as I doubt it will change the class of the object passed as first argument.DatabaseStatementPrefetch::executeto usePDO::FETCH_CLASSto (pre-)fetch the data. But (pre-)creating all the instances onexecute(and stroring them inDatabaseStatementPrefetch::$data) will prevent them from being garbage collected before the statement is.Comment #2
pbuyle commentedComment #3
catchIt does need an 8.x patch first, but a single patch should apply to both versions.
Comment #4
tim.plunkettComment #5
alaa commentedsubscribing
Comment #6
sachbearbeiter commentedsub
Comment #7
leup commentedsubscribe
Comment #8
damien tournoud commentedI 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).
Comment #9
tim.plunkettThe original issue for this bug had a workaround committed, and this issue has stagnated.
@mongolito404, are you still going to work on this?
Comment #10
pbuyle commented@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.
Comment #10.0
pbuyle commentedFix a typo
Comment #12
daffie commentedThis issue is a duplicate of #1476782: DatabaseStatementPrefetch::current PHP function array_unshift() are used incorrectly.