Problem/Motivation
When running PHP 7.2, the each() function is now deprecated as per the php.net migration notes for 7.2:
https://secure.php.net/manual/en/migration72.deprecated.php#migration72....
Deprecation notice raised:
Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in FieldCollectionItemEntity->fetchHostDetails() (line 302 of sites/all/modules/field_collection/field_collection.entity.inc).
Proposed resolution
In field_collection.entity.inc, replace:
list($this->hostEntityType, $data) = each($result);
with:
$this->hostEntityType = key($result);
$data = current($result);
Arcane note: technically, if we wanted to keep absolute parity with the code we're replacing, we would use next() rather than current() since the call we're replacing, each(), advances the internal array pointer, which next() does but current() does not. However, the array is not used further, meaning that advancing the array pointer is an incidental byproduct of using each() rather than something we need to retain, and using next() for no reason would only be confusing.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | field_collection-php72-beta11-2936874-20.patch | 571 bytes | sickness29 |
| #16 | interdiff.txt | 525 bytes | nedjo |
| #16 | field_collection-each-2936874-16.patch | 548 bytes | nedjo |
Comments
Comment #2
barry_fisher commentedPatch attached for review.
Comment #3
bkosborneComment #4
bkosborneLooks good to me
Comment #5
bkosborneHere's a version of the patch that applies cleanly against 7.x-1.0-beta12. The original patch is the one that should be committed. Has a .txt extension which I think prevents the tests from running.
Comment #6
mrgoodfellow commentedAfter applying this patch and when editing a draft of a new node I am getting the following error:
Notice: Undefined index: in FieldCollectionItemEntity->fetchHostDetails() (line 394 of /data/drupal/sites/all/modules/contrib/field_collection/field_collection.module).
any ideas?
Comment #7
czigor commentedJust a reroll for latest dev.
Comment #8
herved commentedI can confirm the notice reported by mrgoodfellow when applying patch #5 on 7.x-1.0-beta12.
Latest dev added https://cgit.drupalcode.org/field_collection/commit/?h=7.x-1.x&id=c1f704... from #2382089: Logic issue with fetchHostDetails() causes false "the host entity cannot be changed" error in updateHostEntity() which adds a check on empty results.
Patch #7 looks good to me with latest dev, but I think the logic in there could be simplified a bit.
Here's an attempt, let me know if that adds any value.
Comment #9
herved commentedComment #11
herved commentedArg.. small confusion there.
This should work.
Comment #12
heyyo commentedThanks for the patch. To make it work with issue https://www.drupal.org/project/field_collection/issues/2833061
I had to keep the other modifications from the other patch:
Comment #13
adam1 commentedDear @heyyo, I am not very savvy in coding, so: how can I apply your combination? Is your above if-statement the combined version and I can just replace the code in the original module with this statement?
Comment #14
mrgoodfellow commentedPatch from #11 is working well with my testing.
Do we have a timeline for this update to be included with a PHP 7.2 compatible release?
Comment #15
lamp5Patch from #11 works well. Thanks.
Comment #16
nedjoChanges were introduced in #8 and #11 with the following comment:
To answer the question of whether this change adds value: it may be true that the logic of the existing code could be improved, but if so that should be done in a follow-up issue as it's unrelated to the bug here. Introducing such changes here make it a lot more difficult to determine whether the patch successfully resolves the reported bug without introducing new ones. Here, we should do the minimum needed to update the deprecated code.
Attaching an updated patch. The only change from the version in #7 is to use
current()alongsidekey(). The interdiff is relevant to the patch in #7.Arcane note: technically, if we wanted to keep absolute parity with the code we're replacing, we would use next() rather than
current()since the call we're replacing,each(), advances the internal array pointer, whichnext()does butcurrent()does not. However, the array is not used further, meaning that advancing the array pointer is an incidental byproduct of usingeach()rather than something we need to retain, and usingnext()rather thancurrent()for no reason would only be confusing.Comment #17
nedjoLinking to parent issue, #3014925: [META] Plan for 7.x-1.0-beta13: PHP 7.2 compatibility.
Comment #18
kevineinarsson commented#16 works. Marking this issue as RTBC.
Comment #19
samuel.mortensonHere's a re-roll of #16 for the beta12 tag.
Comment #20
sickness29 commentedRe-roll of #16 for the beta11 tag.
Comment #22
jacob.embree commentedResetting to RTBC in accordance with #18. The following two patches are not against the latest dev.
Patches not against the latest dev should be marked "Do not test" from the select list next to the file name before upload.
Comment #23
max lovric commentedHere is patch for 7.x-1.0-beta11 version :)
Comment #25
sjerdoResetting to RTBC per #16. The patch in #23 is not against the latest dev and equals the patch in #20.
@Max Lovric please read the comments, since the patch was already supplied. Also your patch uses an incorrect base.
Comment #26
mrgoodfellow commentedIn order to get all count() and each() errors resolved on this module for PHP 7.2 Compatibility I had to apply both patches:
field_collection-2936874-php72-11.patch.txt
as well as: field_collection-php72-countable-2992575-17.patch.txt
from: https://www.drupal.org/project/field_collection/issues/2992575
Comment #28
nedjoThanks, applied!
Comment #30
Joe Schwartz commentedSo, can someone please point me to the final Drupal 7 PHP 7.2 patch?
Comment #31
jweowu commentedThe committed patch (for this specific issue) was #16:
* https://www.drupal.org/files/issues/2018-11-19/field_collection-each-293...
* https://git.drupalcode.org/project/field_collection/commit/d5456f362b3eb...
* https://git.drupalcode.org/project/field_collection/commit/d5456f362b3eb...