Make WordPress Core

Opened 7 years ago

Closed 5 years ago

#43627 closed defect (bug) (fixed)

Method call uses 2 parameters, but method signature uses 1 parameters

Reported by: kaggdesign's profile kaggdesign Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: 4.9.4
Component: Script Loader Keywords: has-patch dev-feedback early
Focuses: Cc:

Description

wp-includes/class.wp-dependencies.php, line 106

Method do_item() called with 2 parameters:

				if ( $this->do_item( $handle, $group ) ) {
					$this->done[] = $handle;
				}

Method signature has 1 parameter (same file, line 125)

	public function do_item( $handle ) {
		return isset( $this->registered[ $handle ] );
	}

Even taking into consideration further inheritance, second parameter $group should be added to method signature, to avoid code misunderstanding, and Code Smell warning in PhpStorm.

Attachments (1)

43627.diff (1.5 KB) - added by soulseekah 7 years ago.

Download all attachments as: .zip

Change History (15)

#1 @SergeyBiryukov
7 years ago

  • Component changed from General to Script Loader
  • Milestone changed from Awaiting Review to 5.0

Previously: #24770

This is simple class inheritance. The do_item() method in class.wp-dependencies.php is a placeholder meant to be overwritten when extending the class. When handling scripts WP_Dependencies is extended with WP_Scripts. So $this->do_item() executes the do_item() method of WP_Scripts that expects the second argument. (The WP_Dependencies::do_item() is still used in WP_Scripts but note how it's called with parent::do_item($handle).)

#24770 was not about the signature though, but rather about a missing wp_footer() call in a theme.

Let's use this ticket to add $group parameter to WP_Dependencies::do_item() for consistency with WP_Scripts::do_item(), to avoid further confusion.

Last edited 7 years ago by SergeyBiryukov (previous) (diff)

@soulseekah
7 years ago

#2 @SergeyBiryukov
7 years ago

  • Keywords has-patch added

#3 @SergeyBiryukov
7 years ago

  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#4 @pento
6 years ago

  • Milestone changed from 5.0 to 5.1

#5 @pento
6 years ago

  • Keywords dev-feedback added
  • Milestone changed from 5.1 to 5.2

This change needs review, particularly considering side effects of changing the signature of WP_Dependencies::do_item().

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


6 years ago

#7 @audrasjb
6 years ago

  • Keywords early added
  • Milestone changed from 5.2 to 5.3

As per today's bug scrub, we are going to punt this one to the next release since beta 3 and RC are approaching.
Adding early keyword so it can be tested early in the release cycle.

#8 @azaozz
5 years ago

  • Milestone 5.3 deleted
  • Resolution set to worksforme
  • Status changed from reviewing to closed

At some point it was possible (still is?) to use WP_Dependencies as a separate "package". As per comment 5, thinking it's not a good idea to change the signature of WP_Dependencies::do_item().

Closing as worksforme, please feel free to reopen with an investigation of possible side effects.

#9 @SergeyBiryukov
5 years ago

  • Resolution changed from worksforme to maybelater

#10 @SergeyBiryukov
5 years ago

  • Milestone set to Future Release
  • Resolution maybelater deleted
  • Status changed from closed to reopened

Would be nice to clean this up at some point.

For reference, only 6 plugins from the directory extend WP_Dependencies:

  • 3 of them just include BackPress files and should not be affected.
  • 2 of them might be affected:
    • AdFever for WordPress, last update: 10 years ago.
    • WP HTML Imports Helper, last update: 4 years ago.
  • None of them has more than 10 active installs.

Worst case scenario, there might be warnings like these: https://3v4l.org/2iS9g, but no fatal errors.

Changing the Walker::walk() and ::paged_walk() signatures in [46442] appears to have more impact.

#11 @SergeyBiryukov
5 years ago

  • Milestone changed from Future Release to 5.5

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


5 years ago

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


5 years ago

#14 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 47769:

Script Loader: Add the $group parameter to WP_Dependencies::do_item().

Previously, the method was called with two parameters in ::do_items(), while the method signature only included one parameter.

Technically, this was not an issue as WP_Dependencies::do_item() is a placeholder meant to be overwritten when extending the class. When handling scripts, WP_Dependencies is extended with WP_Scripts, and the $group parameter was only used in WP_Scripts::do_item(), which does expect a second argument.

However, officially adding the parameter to WP_Dependencies::do_item() signature prevents code misunderstanding and avoids a warning in PHP code inspection tools.

Props kaggdesign, soulseekah, azaozz, SergeyBiryukov.
Fixes #43627.

Note: See TracTickets for help on using tickets.