类我有OOP PHP代码:获取父扩展在PHP
class a {
// with properties and functions
}
class b extends a {
public function test() {
echo __CLASS__; // this is b
// parent::__CLASS__ // error
}
}
$b = new b();
$b->test();
我有几个父类(正常和抽象)和许多子类。子类扩展父类。所以当我在某个时候实例化孩子时,我需要找出我调用的父母。
比如函数b::test()
会从我的B类返回a
我怎样才能获得(从我的代码)类a
?
感谢
阅读此:http://stackoverflow.com/questions/506705/php-get-classname-from-static-call-in-extended-class –