【发布时间】:2015-09-30 06:23:16
【问题描述】:
我有一个$class_name = 'B';
还有:
class A
{
static $foo = 42;
static $baz = 4;
}
class B extends A
{
static $bar = 2;
static $baz = 44;
}
我如何知道 $class_name::$foo 是 $class_name 的静态属性还是继承的静态属性?
我需要以下结果:
$class_name = 'A';
isOwnStaticProperty($class_name, 'foo'); //TRUE : is a static property of this class
$class_name = 'B';
isOwnStaticProperty($class_name, 'foo'); //FALSE : is NOT a static property of this class
$class_name = 'B';
isOwnStaticProperty($class_name, 'bar'); //TRUE : is a static property of this class
$class_name = 'A';
isOwnStaticProperty($class_name, 'bar'); //FALSE : is NOT a static property of this class
$class_name = 'B';
isOwnStaticProperty($class_name, 'baz'); //TRUE : is a static property of this class
$class_name = 'A';
isOwnStaticProperty($class_name, 'baz'); //TRUE : is a static property of this class
isOwnStaticProperty()功能如何实现?
【问题讨论】:
-
你可以在php.net/manual/en/function.get-parent-class.php查看
get_parent_class -
是的,但是之后呢?如何检查它是类还是父类的属性?
-
我用你的 las 更新更新我的答案,检查代码我现在会写解释
标签: php class oop inheritance static