If you recently updated your PHP version above 7.4 and encountered the “Fatal Error After Updating PHP version (wp-includes/class-wp-widget.php on line 163),” you’re not alone. This issue is quite common among WordPress users who are maintaining websites with legacy themes or plugins. The good news is that it’s easily fixable with a simple tweak to your code. In this guide, we’ll walk you through the reason behind this error and how to resolve it without breaking your site.
Understanding the Fatal Error in wp-includes/class-wp-widget.php on line 163
The specific error you’re likely seeing looks something like this:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /path/to/your/site/wp-includes/class-wp-widget-factory.php on line 61 and exactly 2 expected in /path/to/your/site/wp-includes/class-wp-widget.php on line 163
This message indicates a problem with how widgets are being initialized in WordPress when the PHP version is updated beyond 7.4. From PHP 8.0 onwards, the behavior regarding function argument handling became stricter. That means if a constructor requires arguments and they aren’t provided, PHP throws a fatal error.
Why This Error Occurs
This fatal error typically arises after updating to PHP 8.0 or later because of how the widget objects are being instantiated in WordPress core files. Specifically, the issue is triggered in this line of code in wp-includes/class-wp-widget-factory.php
:
$this->widgets[ $widget ] = new $widget();
In older PHP versions, calling a class constructor with no arguments—even when the constructor expected some—didn’t result in a fatal error. However, PHP 8.0 and later versions enforce stricter type checking and argument requirements.
Where is This Located?
The problematic line is located in the following file:
File Path: wp-includes/class-wp-widget-factory.php
Line: 61
How to Fix the Fatal Error in wp-includes/class-wp-widget.php on line 163
Thankfully, fixing this doesn’t require rolling back your PHP version or downgrading WordPress. Instead, you can fix it with a simple code change.
Step-by-Step Instructions:
- Access Your WordPress Installation Files:
- Use FTP software like FileZilla or your web host’s file manager.
- Navigate to the File:
- Go to
/wp-includes/class-wp-widget-factory.php
- Go to
- Locate Line 61 or 62 or 63:
- You should see the following line of code in older PHP versions, calling a class constructor with no arguments—even when the constructor expected some—didn’t result in a fatal error. However, PHP 8.0 and later versions enforce stricter type checking and argument requirements.
Where is This Located?
The problematic line is located in the following file:
File Path:
wp-includes/class-wp-widget-factory.php
Line: 61How to Fix the Fatal Error in wp-includes/class-wp-widget.php on line 163
Thankfully, fixing this doesn’t require rolling back your PHP version or downgrading WordPress. Instead, you can fix it with a simple code change.
Step-by-Step Instructions:
Access Your WordPress Installation Files:
Use FTP software like FileZilla or your web host’s file manager.
Navigate to the File:
Go to /wp-includes/class-wp-widget-factory.php
Change this:
$this->widgets[ $widget ] = new $widget();
To:
$this->widgets[ $widget ] = new $widget( $widget, $widget );
Save the File and Clear Cache:
After saving your changes, clear your WordPress cache if you’re using caching plugins like W3 Total Cache or WP Super Cache.
Reload Your Site.
Why This Fix Works
The change essentially provides the required arguments to the __construct()
function of the widget class. In most WordPress widget classes, the constructor expects two arguments: an ID and a name. By passing $widget
for both, the code satisfies the function’s argument requirements.
This ensures compatibility with PHP 8.0 and newer versions without needing to alter multiple core files or plugin code.