【发布时间】:2016-03-30 12:09:45
【问题描述】:
我有两个类(模型和用户),但我有一个问题,所以我试图用一个简单的例子来解释它:
class person
{
protected static $todo ="nothing";
public function __construct(){}
public function get_what_todo()
{
echo self::$todo;
}
}
class student extends person
{
protected static $todo ="studing";
}
$s = new student();
$s->get_what_todo(); // this will show the word (nothing)
//but I want to show the word (studing)
请给我一个解决方案,但我不想在学生课上写任何函数,我只想在那里声明:),谢谢:)
【问题讨论】:
-
Late static binding.....
echo self::$todo;和echo static::$todo;之间的区别 -
非常感谢你,你刚刚救了我的命,如果你愿意,可以添加你的评论作为答案:) :)
标签: php inheritance static-members