Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP严格标准在未重写超类方法的子类上引发错误_Php_Class_Standards_Strict_Implements - Fatal编程技术网

PHP严格标准在未重写超类方法的子类上引发错误

PHP严格标准在未重写超类方法的子类上引发错误,php,class,standards,strict,implements,Php,Class,Standards,Strict,Implements,我遇到以下警告: 严格标准:FGLU_Activity::delete()的声明应与中的FGLU_Entity::delete($id,$commit=true)兼容 FGLU_活动扩展FGLU_实体,不重写static::delete方法 关于如何在下次遇到此错误时避免此错误,是否有任何提示 <?php class FGLU_Entity { /* * ... */ static function delete($id,$commit=true

我遇到以下警告:

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

FGLU_活动扩展FGLU_实体,不重写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;

    /*
     * ...
     */

}

FGLU_活动扩展FGLU_实体,不覆盖静态 ::删除方法

关于如何在下次遇到此错误时避免此错误,是否有任何提示

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

    /*
     * ...
     */

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

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


要么这样,要么我真的错过了什么。静态方法仍然受可见性、继承性等标准规则的约束,因此这不是真正的问题。

向我们展示这两个类的代码?将其添加到问题中,而不是像commentChild
delete
方法将删除什么?也许它也需要
$id
作为参数?我省略了类中的大部分代码,但关键是在子类中没有定义static delete方法。它只是从基类继承的。代码是有效的(记录被删除),但是当PHP按照严格的标准执行时,它会抛出一个警告。这个类中还有其他名为
delete
的符号吗?你完全正确,我错过了子类中的delete方法。谢谢