在部署项目时出现:Strict standards: Declaration of ... should be compatible with that of ...错误,我使用的是php 5.3.3
<?php
abstract class A {
// 方法无参数
public static function foo(){ echo 'bar'; }
}
abstract class B extends A {
// 方法有参数
public static function foo($str){ echo $str; }
}
?>
解决方法:
<?php
abstract class A {
// 方法无参数
public static function foo(){ echo 'bar'; }
}
abstract class B extends A {
// 方法有参数
public static function foo($str = NULL){ echo $str; }
}
?>
这是由于 php 5.3版本后。要求继承类必须在父类之后定义。否则就会出现Strict Standards: PHP Strict Standards: Declaration of .... should be compatible with that of .... 的错误提示。也就是说必须父类在前,继承类在后。
PHP5.3+继承类方法兼容性问题

本文解决了在PHP5.3及以上版本中遇到的继承类方法声明不兼容的问题,通过调整子类方法参数默认值实现,确保了继承类与父类方法签名一致。
152

被折叠的 条评论
为什么被折叠?



