[wp-trac] [WordPress Trac] #60725: class-wp-widget fatal error in PHP 8.2
WordPress Trac
noreply at wordpress.org
Thu Mar 7 13:37:15 UTC 2024
#60725: class-wp-widget fatal error in PHP 8.2
--------------------------+-----------------------------
Reporter: markhowe | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 6.4.3
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to
function WP_Widget::__construct(), 0 passed in
/nas/content/live/bishopslawdev1/wp-includes/class-wp-widget-factory.php
on line 62 and at least 2 expected in /nas/content/live/bishopslawdev1/wp-
includes/class-wp-widget.php:163
This error seems to have been identified previously, but without pointing
to the file where the source of the problem lies (i.e. class-wp-widget-
factory.php ). A simple Google search shows that a number of people who
are using a theme that makes use of the wp-widget class have seen this
fatal error when they have tried to upgrade to PHP 8.
Comparing the 'new $widget()' call in class-wp-widget-factory.php with the
constructor in class-wp-widget.php shows clearly that the constructor
expects at least two arguments, but that class-wp-widget-factory.php
supplies none. The fix that has been suggested (and which works on PHP
8.2) is the following:
public function register( $widget ) {
if ( $widget instanceof WP_Widget ) {
$this->widgets[ spl_object_hash( $widget ) ] = $widget;
} else {
// $this->widgets[ $widget ] = new $widget(); <---- the
current line 62 ---------
$this->widgets[ $widget ] = new $widget($widget, $widget); //
fix for PHP 8
}
}
Perhaps there is a more elegant solution, but this does work, and I have
this version of the file running on a live server. Of course, each time I
upgrade to the latest version of WordPress this file gets overwritten...
So I would be very grateful if the current file could be made PHP 8 ready.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60725>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list