[wp-trac] [WordPress Trac] #56127: WP_Widget constructor throws fatal ArgumentCountError

WordPress Trac noreply at wordpress.org
Mon Aug 7 21:00:17 UTC 2023


#56127: WP_Widget constructor throws fatal ArgumentCountError
-------------------------------------------+-------------------------------
 Reporter:  firefly2000                    |       Owner:  (none)
     Type:  defect (bug)                   |      Status:  new
 Priority:  normal                         |   Milestone:  Awaiting Review
Component:  Widgets                        |     Version:  6.0
 Severity:  normal                         |  Resolution:
 Keywords:  needs-patch reporter-feedback  |     Focuses:  coding-standards
-------------------------------------------+-------------------------------

Comment (by hellofromTonya):

 Replying to [comment:2 trevordearham]:
 > I just updated to WordPress 6.0.2 successfully and then to PHP 8.0. When
 switching to PHP 8.0, I got the same error mentioned:
 >
 > `Fatal error: Uncaught ArgumentCountError: Too few arguments to function
 WP_Widget::__construct(), 0 passed in /wp-includes/class-wp-widget-
 factory.php on line 61 and at least 2 expected in /wp-includes/class-wp-
 widget.php:162`
 >
 > The code can be seen in the release code for WordPress 6.0.2
 https://github.com/WordPress/WordPress/blob/6.0.2/wp-includes/class-wp-
 widget-factory.php#L61.
 >
 > Applying the suggested patch to that line causes the code to work, but
 probably not the ideal solution.
 >
 > For me the call stack has the Video widget of the FullScene theme
 https://themeforest.net/item/fullscene-portfolio-photography-wp-
 theme/1617432, which is probably not compatible with WordPress 6.

 Hello @trevordearham, I suspect the Video widget in that theme is
 incorrectly doing its constructor. It should have a `__construct()` with
 no parameters defined and then pass the correct information to the base
 `WP_Widget` constructor, per
 [https://developer.wordpress.org/themes/functionality/widgets/ the the
 documentation]. I suggest reaching out to the theme's author to report the
 issue.

 >It appears to be passing a string instead of an instance of WP_Widget,
 but I assume the code path should allow this.

 Passing its widget classname as a string is correct and the way WordPress
 Core does it too.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56127#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list