Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#17911 closed defect (bug) (invalid)

WP_Dependencies::remove() may generate PHP Warning

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


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])) {

Change History (5)

#1 @kawauso
9 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
8 years ago

  • Keywords needs-patch added

#3 @azaozz
8 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 )

#4 @azaozz
8 years ago

  • Keywords close added; needs-patch removed

#5 @SergeyBiryukov
8 years ago

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