Problem/Motivation
I couldn't find an existing issue for this exception.
exception: [Notice] Line 926 of modules/forum/forum.module: Trying to access array offset on value of type null
Here's the relevant code (including line numbers initially):
914 function forum_get_topics($tid, $sortby, $forum_per_page) {
915 global $user, $forum_topic_list_header;
916
917 $forum_topic_list_header = array(
918 NULL,
919 array('data' => t('Topic'), 'field' => 'f.title'),
920 array('data' => t('Replies'), 'field' => 'f.comment_count'),
921 array('data' => t('Last reply'), 'field' => 'f.last_comment_timestamp'),
922 );
923
924 $order = _forum_get_topic_order($sortby);
925 for ($i = 0; $i < count($forum_topic_list_header); $i++) {
926 if ($forum_topic_list_header[$i]['field'] == $order['field']) {
927 $forum_topic_list_header[$i]['sort'] = $order['sort'];
928 }
929 }
Proposed resolution
Fix the bug; avoid the PHP exception / notice in PHP 7.4.
Remaining tasks
Patch, review, commit etc..
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
See parent issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3125824-8.patch | 566 bytes | taran2l |
Comments
Comment #2
mcdruid commentedComment #3
mcdruid commentedConfirmation that this patch prevents the forum module exceptions in the current baseline test over in #3081386-70: [META] Fully support PHP 7.4 in Drupal 7:
Comment #4
taran2lMy idea was to fix it in a slightly different way:
As 0 indexed element is NULL, so just skip it
Comment #5
taran2lComment #6
avpadernoComment #7
avpadernoComment #8
taran2lComment #9
taran2lConfirmation that patch in #8 has the same effect as #2:
Comment #10
mcdruid commentedThanks @Taran2L, I like the approach of starting at index 1.
I wonder if it's worth a comment to point out that we're deliberately skipping the first item? Probably not necessary.
In D8 this code is in
\Drupal\forum\ForumManager::getTopics()and there is no NULL first item.I've tweaked the issue title to match recent commit messages.
Comment #11
taran2l@mcdruid, I think a comment will add some clarity
Comment #12
mcdruid commentedSuggested comment to add on commit, before the for loop:
Comment #13
fabianx commentedRTBM - thanks all!
And I agree the comment to add looks good.
Comment #15
mcdruid commentedThanks everyone!