Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arknoll’s picture

Working on this.

longwave’s picture

@arknoll: You might want to use the "assigned" field to indicate this.

arknoll’s picture

Status: Active » Needs review
FileSize
525 bytes

Removed variable.

Status: Needs review » Needs work

The last submitted patch, core-remove-variable-2002708.patch, failed testing.

kerasai’s picture

Status: Needs work » Needs review
FileSize
525 bytes

Looks like patch in #3 was created backwards, as it was trying to add the line instead of remove it. Let's give this a shot.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

Good to go

catch’s picture

Status: Reviewed & tested by the community » Needs review

This looks like a bug to me rather than just an unused variable - isn't it trying to ensure that $options is an array in the return value?

 foreach ($module_libraries[$key]['js'] as $file => $options) {
          if (is_scalar($options)) {
            // The JavaScript or CSS file has been specified in shorthand
            // format, without an array of options. In this case $options is the
            // filename.
            $file = $options;
            $options = array();
          }

So it should write options back to the array (or act on a reference in the foreach()) rather than just discarding.

somepal’s picture

if (is_scalar($options))

checks if its scalar and intends to make $options available as array (for the next foreach pass maybe) if its the one. But initializing in this manner at the end of the foreach() pass, wouldn't serve that purpose. its not used further down the line as well. hence removed in the patch.

kerasai’s picture

Assigned: Unassigned » somepal

@catch Not sure how much sense it makes to set $options to an empty array just to assign it a value on the next operation as it iterates through the foreach. On last pass $options remain set, but not used anywhere in the remainder of the function. Sure seems unused to me.

#5 kept testbot happy and #8 is identical, I think this is RTBC. Since I've contributed code on this one, I'll let you all hash it out.

longwave’s picture

Instead of

$file = $options;
$options = array();

do we need

unset($module_libraries[$key]['js'][$file]);
$file = $options;

To ensure the original $file key is unset by the end of the foreach?

somepal’s picture

@longwave sorry could not agree that it was an unset attempt and I think we wouldn't need

unset($module_libraries[$key]['js'][$file]);

there, as

$module_libraries[$key]['js'][$file]['version']

is referred again as -

$module_libraries[$key]['js'][$file]['version'] = $module_libraries[$key]['version'];

At the same time, feels that it is not an attempt to initialize the variable to an array, as it wouldn't work that way, foreach() only works on the copy of the array unless passed as reference.

So the conclusion we should delete the line

$options = array();

safely and got ahead with patch #5 2002708-5-remove_unused_variables_common_inc.patch or #8 2002708_unused-local-var_8.patch

somepal’s picture

Assigned: somepal » Unassigned
longwave’s picture

The comment above this block says "The JavaScript or CSS file has been specified in shorthand format, without an array of options. In this case $options is the filename". Firstly this is wrong because the loop explicitly looks at JavaScript only, not CSS, and secondly this "shorthand format" does not appear to be documented anywhere. The source of data for this loop is hook_library_info(), and the documentation there for the 'js' key says "An array of JavaScript elements; each element's key is used as $data argument, each element's value is used as $options array for drupal_add_js()". So, perhaps we should remove this check for the "shorthand format" entirely?

longwave’s picture

Issue summary: View changes

Updated issue summary.

jibran’s picture

Status: Needs review » Needs work

The last submitted patch, 8: 2002708_unused-local-var_8.patch, failed testing.

rahul.shinde’s picture

Assigned: Unassigned » rahul.shinde
Issue summary: View changes
rahul.shinde’s picture

Status: Needs work » Needs review
FileSize
496 bytes

Tried re-rolling patch but failed. So created altogether new patch and submitting.

xjm’s picture

Title: Improve performance by removing unused local variables - core/includes/common.inc » Remove unused local variables from core/includes/common.inc

The performance impact of this is negligible, so retitling.

elgordogrande’s picture

Status: Needs review » Reviewed & tested by the community

The $options variable may have been used previously in this scope, but appears to no longer be the case, so it is safe to remove.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.