【发布时间】:2016-03-30 16:38:36
【问题描述】:
这是我的班级声明
abstract class person {
const NAME='person';
public static function get_name(){
return self::NAME;
}
abstract public function get_description();
}
class me extends person{
const NAME = "me";
public function get_description(){
return "this describe " . self::NAME;
}
}
如您所见,const 名称在类 person 和 me 中都声明了两次。 我在“person”类中声明它,因为它在那里我们在方法 get_name() 的实现中使用它 我也在“我”类中声明它,因为我想要得到“我”的名字。
所以当我打电话时
echo me::get_name()
我希望它返回“我”
实际上它返回“人”,所以我在这里缺少什么,所以它会返回“我”。
谢谢
【问题讨论】:
标签: php oop inheritance abstract-class