PHP 严格标准在不覆盖超类方法的子类上抛出错误
PHP Strict Standards throwing error on subclass that does not override superclass method
我遇到以下警告:
Strict Standards: Declaration of FGLU_Activity::delete() should be compatible with FGLU_Entity::delete($id, $commit = true) in ...
FGLU_Activity 扩展 FGLU_Entity 并且不覆盖静态 ::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_Activity extends FGLU_Entity and does NOT override the static
::delete method.
Any hints as to how to avoid this error the next time i encounter it?
您有一个子class 包含一个 delete() 方法,其参数与父 class 中的 delete() 方法中的参数不匹配。这不是真正的错误。如果功能不匹配,则重命名子方法以显示此功能,或者如果匹配但父方法中的参数是多余的,请添加 FGLU_Activity($id=NULL,$commit=NULL).
如果您没有在子 class 中也声明该方法,则不会出现此错误。
要么是这样,要么是我真的漏掉了什么。静态方法仍然受关于可见性、继承等的标准规则的约束,所以这不是这里的真正问题。
我遇到以下警告:
Strict Standards: Declaration of FGLU_Activity::delete() should be compatible with FGLU_Entity::delete($id, $commit = true) in ...
FGLU_Activity 扩展 FGLU_Entity 并且不覆盖静态 ::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_Activity extends FGLU_Entity and does NOT override the static ::delete method.
Any hints as to how to avoid this error the next time i encounter it?
您有一个子class 包含一个 delete() 方法,其参数与父 class 中的 delete() 方法中的参数不匹配。这不是真正的错误。如果功能不匹配,则重命名子方法以显示此功能,或者如果匹配但父方法中的参数是多余的,请添加 FGLU_Activity($id=NULL,$commit=NULL).
如果您没有在子 class 中也声明该方法,则不会出现此错误。
要么是这样,要么是我真的漏掉了什么。静态方法仍然受关于可见性、继承等的标准规则的约束,所以这不是这里的真正问题。