php 方法重写,报错: Declaration of should be compatible with that

详细描述为:https://bugs.php.net/bug.php?id=46851

abstract class A {
// 方法无参数
public static function dom(){}
}
 
abstract class B extends A {
// 方法有参数
public static function dom($str=null){ echo $str; }
}
?>

会产生一个类似下面E_STRICT级别的警告:

Strict standards: Declaration of ... should be compatible with that of ...

 

abstract class B extends A {
// 方法有参数
public static function foo($str=null){ echo $str; }
}
?>

类B在重写dom方法时需要为新加入的参数指定一个默认值

你可能感兴趣的:(后台)