Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
StatementPrefetch::current() contains this snippet:
case \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE:
$class_name = array_unshift($this->currentRow);
That is syntactically wrong, as array_unshift() takes 2 arguments and returns a new array. It probably should be array_shift().
It wasn't caught because FETCH_CLASS is apparently the only fetch mode that 1) We don't test properly and 2) We don't actually use in core. :-) Also, StatementPrefetch is only used by SQLite, which until recently wasn't even tested.
Proposed resolution
1) Fix the bug.
2) Add a test to
https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Tests%...
for the missing fetch modes.
Comment | File | Size | Author |
---|---|---|---|
#4 | fix-bug-fetch-class-2499875-4.patch | 1.9 KB | a_thakur |
Comments
Comment #1
cilefen CreditAttribution: cilefen commentedIs the title for this correct? It seems like a code bug, not a documentation style bug.
Comment #2
Crell CreditAttribution: Crell at Palantir.net commentedOops. Yes, I did a clone issue and forgot to change that.
Comment #3
a_thakur CreditAttribution: a_thakur as a volunteer and at Srijan | A Material+ Company commentedWorking on this.
Comment #4
a_thakur CreditAttribution: a_thakur as a volunteer and at Srijan | A Material+ Company commented* Replaced array_unshift() with array_shift().
* Wrote test case for FETCH_LAZY
* Test cases for FETCH_INTO and \PDO::FETCH_CLASS | \PDO::FETCH_CLASSTYPE are remaining. Any help regarding these would be great.
Comment #5
Crell CreditAttribution: Crell at Palantir.net commentedThanks. It's not object fetch that isn't being tested, though. It's CLASS fetch. Ie, loading a record directly into a PHP class. Check the docs for PDO::FETCH_CLASS. (I don't know what FETCH_CLASSTYPE does, honestly.)
Comment #6
a_thakur CreditAttribution: a_thakur as a volunteer and at Srijan | A Material+ Company commentedComment #7
BerdirClosing as duplicate of #1476782: DatabaseStatementPrefetch::current PHP function array_unshift() are used incorrectly