Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#17911 closed defect (bug) (invalid)

WP_Dependencies::remove() may generate PHP Warning

Reported by: ftrudeau's profile ftrudeau Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1.3
Component: Warnings/Notices Keywords: close
Focuses: Cc:

Description

The following code will always generate a PHP Warning: Illegal offset type in unset, on line 159 of /wp-includes/class.wp-dependencies.php

global $wp_styles;
foreach ($wp_styles->registered AS $handle) $wp_styles->remove($handle);

... and here is a simple fix :

if (@isset($this->registered[$handle])) {
   unset($this->registered[$handle]);
}

Change History (5)

#1 @kawauso
13 years ago

PHP is throwing the warning because $handle being passed is the whole WP_Dependency object for the style, rather than it's actual slug, which is incorrect usage. A workaround would be to check is_string() for $handle.

#2 @SergeyBiryukov
13 years ago

  • Keywords needs-patch added

#3 @azaozz
13 years ago

WP_Dependencies::remove() expects a single $handle (the name a script or stylesheet was registered with) or an array of handles if you want to remove more than one at the same time. WP_Dependencies::enqueue() and WP_Dependencies::dequeue() work in the same way.

Not sure where the above example code comes from but it seems it needs to be:

foreach ( $wp_styles->registered AS $handle => $object )
  $wp_styles->remove($handle);

#4 @azaozz
13 years ago

  • Keywords close added; needs-patch removed

#5 @SergeyBiryukov
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.