Problem/Motivation
Within theme_system_modules_details() a nested foreach loop re-assigns the parent foreach loops iterator ($key).
// Iterate through all the modules, which are children of this element.
foreach (Element::children($form) as $key) {
....
...
foreach (array('help', 'permissions', 'configure') as $key) {
$links .= drupal_render($module['links'][$key]);
}
}
since $key is not used below that point, there isn't any current breakage. However, this is fragile, and should code later need that key below, would cause a serious DX issue.
Proposed resolution
Use a different variable name.
Remaining tasks
User interface changes
API changes
Beta phase evaluation
Comments
Comment #1
jhedstromThe patch no longer applies.
Comment #2
martin107 commentedFixed up my own text, and rerolled.
Should come back green.
Comment #3
jhedstromThis simple patch fixes an obvious logic error (even though it hasn't thus far caused problems since the
$keyvariable isn't used again after being redefined).I've updated the issue summary to include a beta phase evaluation.
Comment #4
alexpottCan we use a more meaning name that
$i?Comment #5
alexpottThis issue is a normal bug so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.
Comment #6
martin107 commentedWhile this it minutely limited in scope - it does not match any of the criteria from the beta phase evaluation template.
I am perfectly open to this issue being shunted to a later release..
To be clear this is just a brittleness in the code ... any future modifications to the function that make use of $key below the next foreach loop
are going to lead to confusion as the loop variable has been inappropriately overwritten.
My real concern is that lint checkers reasonably detail this problem in the "probably bug" section of their error report
and for me it seems bad practice to leave any entries, not matter how small, in this section only to be constantly ignored...
Anyway, as for the patch a more reasonable variable name is $link_type
Comment #7
jhedstromI don't know how to be more clear in the beta phase evaluation. I know bug fixes are allowed, and this is a quite obvious bug (even if it has no current implications since the re-assigned value of
$keyisn't used below that point in the loop).Comment #8
jhedstromI took a stab at simplifying the issue summary, and I updated the beta phase evaluation to note that this fix reduces fragility (which is allowed).
The patch in #6 should address the concerns in #4.
I also added the backport tag since this issue exists in Drupal 7.
Comment #9
catchCommitted/pushed to 8.0.x, thanks!
Moving to 7.x for backport.
Comment #11
serundeputy commentedworking on D7 backport.
Comment #12
serundeputy commentedD7 backport.
Comment #13
martin107 commentedYep that is the fix for the equivalent nested for loop in d7, so +1 from me.
Moving to unassigned, to signal it is free to review.
Comment #14
joachim commentedLooks good.
Comment #17
dcam commentedComment #18
David_Rothstein commentedCommitted to 7.x - thanks!