Opened 16 months ago
Last modified 11 months ago
#19945 new defect (bug)
Bug in ../wp-includes/widgets.php
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Widgets | Version: | 3.3.1 |
| Severity: | normal | Keywords: | reporter-feedback |
| Cc: | info1@…, kpayne@… |
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
SergeyBiryukov — 16 months 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]]
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.
- 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

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?