WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 22 months ago

#19945 new defect (bug)

Bug in ../wp-includes/widgets.php

Reported by: Barti112 Owned by: Barti112
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3.1
Component: Widgets Keywords: reporter-feedback
Focuses: Cc:

Description

in this file there are at some places the following code:

$widget = array_merge($widget, $options);

it is possible that $options is not an array and i become a php-warning.

i think better is to check the arrays before you use this function:

if(is_array($widget) && is_array($options)){

$widget = array_merge($widget, $options);

}

Change History (4)

comment:1 SergeyBiryukov2 years ago

As far as I can see, $options in those places is the result of wp_parse_args(), which always returns an array.

Could you describe the circumstances when $options is not an array?

comment:2 Barti1122 years ago

Here you see a var_dump before the Line 777 of the file "widgets.php":

array(1) { ["id_base"]=> string(5) "pages" }[[BR]]
array(1) { ["id_base"]=> string(8) "calendar" }[[BR]]
array(1) { ["id_base"]=> string(8) "archives" }[[BR]]
array(1) { ["id_base"]=> string(5) "links" }[[BR]]
array(1) { ["id_base"]=> string(4) "meta" }[[BR]]
array(3) { ["id_base"]=> string(4) "text" ["width"]=> int(400) ["height"]=> int(350) }[[BR]]
array(1) { ["id_base"]=> string(10) "categories" }[[BR]]
array(1) { ["id_base"]=> string(12) "recent-posts" }[[BR]]
array(1) { ["id_base"]=> string(15) "recent-comments" }[[BR]]
array(3) { ["id_base"]=> string(3) "rss" ["width"]=> int(400) ["height"]=> int(200) }[[BR]]
array(1) { ["id_base"]=> string(8) "nav_menu" }[[BR]]
array(1) { ["id_base"]=> string(20) "arras_tabbed_sidebar" }[[BR]]
array(1) { ["id_base"]=> string(22) "arras_featured_stories" }[[BR]]
NULL[[BR]]

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /homepages/16/d266165857/htdocs/wsb5144855001/akademie/wp-
includes/widgets.php on line 781[[BR]]
array(1) { ["id_base"]=> string(6) "search" }[[BR]]
array(1) { ["id_base"]=> string(17) "wpcalendargrouped" }[[BR]]
array(1) { ["id_base"]=> string(16) "wpcalendarsimple" }[[BR]]

Perhaps it is a widget of a Plugin, but the general code does not break with an error/warning if there is a bug.

Version 1, edited 22 months ago by scribu (previous) (next) (diff)

comment:3 kurtpayne2 years ago

  • Cc kpayne@… added
  • Keywords dev-feedback added

I can reproduce this by modfying the control_options member after construction. This is a no-no, but because control_options is public, it's not enforced by design.

<?php

class Foo_Widget extends WP_Widget {
        function __construct() {
                parent::WP_Widget( 'foo_widget', 'Foo_Widget', array(
                    'description' => 'A Foo Widget'
                ) );
                $this->control_options = null;
        }
        /** snip **/
}

Results:

PHP Warning:  array_merge() [<a href='function.array-merge'>function.array-merge</a>]: Argument #2 is not an array in ...\wp-includes\widgets.php on line 777

comment:4 scribu22 months ago

  • Keywords reporter-feedback added; dev-feedback removed

I highly doubt the cause of this bug is someone explicitly nulling $this->control_options.

Note: See TracTickets for help on using tickets.