Nicholas Cardot Nicholas Cardot - 3 months ago 33
PHP Question

How do I fix this depracated PHP4 Style constructor issue?

When testing my plugin for compatibility with PHP7, I'm seeing just one error in my plugin.

FOUND 1 ERROR AFFECTING 1 LINE

246 | ERROR | Deprecated PHP4 style constructor are not supported since PHP7


Linked below is the file hosted on GitHub so that you can see it.

https://github.com/warfare-plugins/social-warfare/blob/master/functions/widgets.php

Line 246: function widget($args, $instance) {


This is a class designed to create a WordPress widget, but after Googling a bit, I can't quite see what it's trying to say about the deprecated constructor method. It's not using the same name as the class it's in.

So anyways, what do I need to change on that line to make this fully PHP7 ready?

Answer

Change

function swp_popular_posts_widget() {
    parent::__construct(false, $name = 'Social Warfare: Popular Posts' );
}

to

function __construct() {
    parent::__construct(false, $name = 'Social Warfare: Popular Posts' );
}
Comments