PHP严格标准在不覆盖超类方法的子类上抛出错误

问题描述 投票:-2回答:1

我遇到以下警告:

严格标准:FGLU_Activity :: delete()的声明应与...中的FGLU_Entity :: delete($ id,$ commit = true)兼容

FGLU_Activity扩展了FGLU_Entity并且不覆盖static :: delete方法。

有关如何在下次遇到此错误时避免此错误的任何提示?

<?php

class FGLU_Entity {

    /*
     * ...
     */


    static function delete($id,$commit=true) {

        global $wpdb;

        // first, delete any rows in mapped tables
        $total_count = 0;
        if ($commit) $wpdb->query("START TRANSACTION");

        $instance = new static::$class_name();
        $instance->{static::$key} = $id;

        /*
         * ...
         */

        // then, delete the base row
        $needles = array("xa_table","xa_key","xa_id");
        $threads = array(static::$table,static::$key,$id);
        $sql = fglu_sql(FGLU_SQL_DELETE,$needles,$threads);
        $row_count = $wpdb->query($sql);
        if ($row_count === false) {
            fglu_setError(__METHOD__,"SQL Error<br/>$sql<br/>$wpdb->last_error");
            if ($commit) $wpdb->query("ROLLBACK");
            return false;
        } else {
            if ($commit) $wpdb->query("COMMIT");
            $total_count += $row_count;
            return $total_count;
        }

    }
    /**/


}


class FGLU_Activity extends FGLU_Entity {

    // Keys
    public $activity_id;

    // Required Attributes
    public $name;                   
    public $short;                  

    public $activity_cd;            
    public $display_order;          
    public $private = 0;            
    public $school_visit = 0;       
    public $report = 0;             
    public $capacity = 0;           

    // System Attributes

    public $id_user;
    public $dt_updated;

    /*
     * ...
     */

}

?>

php class standards strict implements
1个回答
0
投票

FGLU_Activity扩展了FGLU_Entity并且不覆盖static :: delete方法。

有关如何在下次遇到此错误时避免此错误的任何提示?

您有一个子类,其中包含一个delete()方法,其参数与父类中的delete()方法中的参数不匹配。这不是一个错误。如果功能不匹配,请重命名子方法以显示此方法,或者如果确实如此,但父项中的参数是多余的,则添加FGLU_Activity($ id = NULL,$ commit = NULL)。

如果您还没有在子类中声明该方法,则不会出现此错误。

无论是那个还是我真的错过了什么。静态方法仍然遵循关于可见性,继承等的标准规则,因此这不是真正的问题。

© www.soinside.com 2019 - 2024. All rights reserved.