• Hi,

    I’ve just tested, if my theme works with WP-6.0.

    At first I’ve tested the theme with WP-6.0 and PHP 7.4. It works without any errors.

    At second I’ve tested the theme with WP-6.0 and PHP 8.0 and I get that error message:

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /customers/1/2/c/site/httpd.www/wp-includes/class-wp-widget-factory.php on line 61 
    and at least 2 expected in /customers/1/2/c/site/httpd.www/wp-includes/class-wp-widget.php:162 
    
    Stack trace:
     #0 /customers/1/2/c/site/httpd.www/wp-includes/class-wp-widget-factory.php(61): WP_Widget->__construct()
    #1 /customers/1/2/c/site/httpd.www/wp-includes/widgets.php(115): WP_Widget_Factory->register('VMenuWidget')
     #2 /customers/1/2/c/site/httpd.www/wp-content/themes/HF_test1/library/widgets.php(251): register_widget('VMenuWidget')
     #3 /customers/1/2/c/site/httpd.www/wp-includes/class-wp-hook.php(307): artWidgetsInit('') 
    #4 /customers/1/2/c/site/httpd.www/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array) 
    #5 /customers/1/2/c/site/httpd.www/wp-includes/plugin.php(476): WP_Hook->do_action(Array) 
    #6 /customers/1/2/c/site/httpd.www/wp-includes/widgets.php(1854): do_action('widgets_init') 
    #7 /customers/1/2/c/site/httpd.www/wp-includes/class-wp-hook.php(307): wp_widgets_init('') 
    #8 /customers/1/2/c/site/httpd.www/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
     #9 /customers/1/2/c/site/httpd.www/wp-includes/plugin.php(476): WP_Hook->do_action(Array) 
    #10 /customers/1/2/c/site/httpd.www/wp-settings.php(598): do_action('init') 
    #11 /customers/1/2/c/site/httpd.www/wp-config.php(80): require_once('/customers/1/2/...') 
    #12 /customers/1/2/c/site/httpd.www/wp-load.php(50): require_once('/customers/1/2/...') 
    #13 /customers/1/2/c/site/httpd.www/wp-admin/admin.php(34): require_once('/customers/1/2/...') 
    #14 /customers/1/2/c/site/httpd.www/wp-admin/index.php(10): require_once('/customers/1/2/...') 
    #15 {main} thrown in /customers/1/2/c/site/httpd.www/wp-includes/class-wp-widget.php on line 162

    In this topic I found allready the error.
    PHP4 to 5
    It looks like this is an issue for any old themes still using deprecated PHP4-style constructors for registering custom widgets.

    This causes the fatal error:

    class My_Custom_Widget extends WP_Widget {
    
    	function My_Custom_Widget() {
    		$this->WP_Widget( false, 'Widget Name' );
    	}
    
    }
    
    add_action( 'after_setup_theme', function() {
    	register_widget( 'My_Custom_Widget' );
    });

    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

    This works as expected:

    class My_Custom_Widget extends WP_Widget {
    
    	function __construct() {
    		parent::__construct( false, 'Widget Name' );
    	}
    
    }
    
    add_action( 'after_setup_theme', function() {
    	register_widget( 'My_Custom_Widget' );
    });

    I changed allready this:

    class VMenuWidget extends WP_Widget {
    
    	function VMenuWidget() {
    		$widget_ops = array('classname' => 'vmenu', 'description' => __('Use this widget to add one of your custom menus as a widget.', THEME_NS));
    		parent::WP_Widget(false, __('Vertical Menu', THEME_NS), $widget_ops);
    	}
    

    into

    class VMenuWidget extends WP_Widget {
    
    	function __construct() {
    		parent::__construct( false, ' VMenuWidget' );
    	}
    

    But then my menu doesn’t work.
    I’ve already tried a few things to solve the problem but without success.
    Maybe you have a solution to my problem. Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You would have to make the constructor public. Therefore, the error only occurs with PHP >= 8.0.

    Dion

    (@diondesigns)

    Your code should be this:

    class VMenuWidget extends WP_Widget {
    	function __construct() {
    		$widget_ops = array('classname' => 'vmenu', 'description' => __('Use this widget to add one of your custom menus as a widget.', THEME_NS));
    		parent::__construct(false, __('Vertical Menu', THEME_NS), $widget_ops);
    	}
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP-6.0 – PHP 8.0 – Uncaught ArgumentCountError’ is closed to new replies.