dpbf62565 2016-10-08 16:02
浏览 116
已采纳

不推荐使用:与其类名相同的方法将不会是PHP的未来版本中的构造函数

how can i fix this error ?

error

facebook.php.php file:

more details more details more details more details more details more details more details more details more details more details more details more details more details more details more details more details more details more details

<?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
    }
}

?>
  • 写回答

1条回答 默认 最新

  • dongwen1871 2016-10-08 18:16
    关注

    Some research...

    Your error was,

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

    Type "methods same name as class php" into google and the first two results are Stack Overflow questions, with lots of info for you.

    The third result is http://php.net/manual/en/language.oop5.decon.php. Always worth reading what php.net has to say about PHP. Click on Google's link and scroll a little way down to find...

    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.

    and...

    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.


    The conclusion...

    From that research we can work out that you need to do a quick update in your code. Replace the line,

    function qwis_facebook_widget() {
    

    with

    function __construct() {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序