已弃用:与 class 同名的方法在 PHP 的未来版本中将不再是构造函数

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

我该如何解决这个错误?

error

facebook.php.php 文件:

更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细更多详细

<?php
/**
 * Plugin Name: Facebook Page Widget
 */

// Load widget
add_action( 'widgets_init', 'qwis_facebook_load_widget' );

// Register widget
function qwis_facebook_load_widget() {
    register_widget( 'qwis_facebook_widget' );
}

// Widget class
class qwis_facebook_widget extends WP_Widget {

    /**
     * Widget setup.
     */
    function qwis_facebook_widget() {

        // Widget settings
        $widget_ops = array( 'classname' => 'qwis_facebook_widget', 'description' => __('Facebook page widget', 'qwis_facebook_widget') );

        // Widget control settings
        $control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => 'qwis_facebook_widget' );

        // Create the widget
        parent::__construct( 'qwis_facebook_widget', __('Facebook Page', 'qwis_facebook_widget'), $widget_ops, $control_ops );

    }

    /**
     * Display widget
     */
    function widget( $args, $instance ) {
        extract( $args );

        // Variables from the widget settings
        $title = apply_filters('widget_title', $instance['title'] );
        $page_url = $instance['page_url'];
        $tabs = $instance['tabs'];
        $header = $instance['header'];
        $cover = $instance['cover'];
        $faces = $instance['faces'];

        // Before widget (defined by theme functions file)
        echo $before_widget;

        // Display widget title
        if ( $title )
            echo $before_title . $title . $after_title;

        ?>
            <div id="fb-root"></div>

            <script>(function(d, s, id) {
              var js, fjs = d.getElementsByTagName(s)[0];
              if (d.getElementById(id)) return;
              js = d.createElement(s); js.id = id;
              js.src = "//connect.facebook.net/ro_RO/sdk.js#xfbml=1&version=v2.7";
              fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));</script>

            <div class="fb-page" data-href="<?php echo esc_url($page_url); ?>" data-tabs="<?php echo ($tabs); ?>" data-small-header="<?php if($header) { echo 'true'; } else { echo 'false'; } ?>" data-adapt-container-width="true" data-hide-cover="<?php if($cover) { echo 'true'; } else { echo 'false'; } ?>" data-show-facepile="<?php if($faces) { echo 'true'; } else { echo 'false'; } ?>"></div>

        <?php

        // After widget (defined by theme functions file)
        echo $after_widget;
    }

    /**
     * Update the widget
     */
    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;

        // Strip tags to remove HTML (important for text inputs)
        $instance['title'] = strip_tags( $new_instance['title'] );
        $instance['page_url'] = strip_tags( $new_instance['page_url'] );
        $instance['tabs'] = strip_tags( $new_instance['tabs'] );
        $instance['header'] = strip_tags( $new_instance['header'] );
        $instance['cover'] = strip_tags( $new_instance['cover'] );
        $instance['faces'] = strip_tags( $new_instance['faces'] );

        return $instance;
    }


    function form( $instance ) {

        // Set up some default widget settings
        $defaults = array( 'title' => 'Find me on Facebook', 'page_url' => '', 'tabs' => '', 'header' => false, 'cover' => false, 'faces' => false );
        $instance = wp_parse_args( (array) $instance, $defaults ); ?>

        <!-- Widget Title: Text Input -->
        <p>
            <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
        </p>

        <!-- page_url -->
        <p>
            <label for="<?php echo $this->get_field_id( 'page_url' ); ?>">Facebook Page URL:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'page_url' ); ?>" name="<?php echo $this->get_field_name( 'page_url' ); ?>" value="<?php echo $instance['page_url']; ?>" />
            <small>e.g. http://www.facebook.com/facebook</small>
        </p>

        <!-- tabs -->
        <p>
            <label for="<?php echo $this->get_field_id( 'tabs' ); ?>">Tabs:</label>
            <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'tabs' ); ?>" name="<?php echo $this->get_field_name( 'tabs' ); ?>" value="<?php echo $instance['tabs']; ?>" />
            <small>e.g. timeline, messages, events</small>
        </p>

        <!-- header -->
        <p>
            <input type="checkbox" id="<?php echo $this->get_field_id( 'header' ); ?>" name="<?php echo $this->get_field_name( 'header' ); ?>" <?php checked( (bool) $instance['header'], true ); ?> />
            <label for="<?php echo $this->get_field_id( 'header' ); ?>">Use Small Header</label>
        </p>

        <!-- cover -->
        <p>
            <input type="checkbox" id="<?php echo $this->get_field_id( 'cover' ); ?>" name="<?php echo $this->get_field_name( 'cover' ); ?>" <?php checked( (bool) $instance['cover'], true ); ?> />
            <label for="<?php echo $this->get_field_id( 'cover' ); ?>">Hide Cover Photo</label>
        </p>

        <!-- faces -->
        <p>
            <input type="checkbox" id="<?php echo $this->get_field_id( 'faces' ); ?>" name="<?php echo $this->get_field_name( 'faces' ); ?>" <?php checked( (bool) $instance['faces'], true ); ?> />
            <label for="<?php echo $this->get_field_id( 'faces' ); ?>">Show Friend's Faces</label>
        </p>

    <?php
    }
}

?>

一些研究...

你的错误是,

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP

在 google 中输入“methods same name as class php”,前两个结果是 Stack Overflow 问题,其中包含大量信息。

第三个结果是http://php.net/manual/en/language.oop5.decon.php。 php.net 对 PHP 的评价总是值得一读。单击 Google 的 link 并向下滚动一点找到...

For backwards compatibility with PHP 3 and 4, if PHP cannot find a __construct() function for a given class, and the class did not inherit one from a parent class, it will search for the old-style constructor function, by the name of the class.

和...

Warning Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.


结论...

根据该研究,我们可以确定您需要快速更新您的代码。替换行,

function qwis_facebook_widget() {

function __construct() {