1
class parent
{
public function methodInParentClass()
{
echo "In parent class called from child class of:";
}
}
class childOne extends parent
{
public $childProperty = "in childOne property";
}
class childTwo extends parent
{
public $childProperty = "in childTwo property";
}
好的,所以我们有两个子类都扩展了父类。现在,如果我叫确定哪个子类正在调用父类'方法
childTwo->methodInParentClass()
问题:
1)methodInParentClass如何确定是哪个类调用它?请注意:通过变量传入名称不可用。 2)如果#1是可以实现的,我怎样称呼孩子的班级资产?我可以实例化一个新类,然后从中调用它,但不会有一些性能问题(特别是因为我的项目可能会这样做很多)?
在此先感谢!
嗯......我误读了get_class的文档,并且觉得它会返回“父”类/属性。我的错。 –