📅  最后修改于: 2023-12-03 15:03:39.348000             🧑  作者: Mango
ReflectionClass getStaticProperties()
函数是PHP反射机制中的一个函数。它用于获取类的静态属性列表或某个类中的静态属性的值。
public static mixed ReflectionClass::getStaticProperties([string $name = ''])
$name
:可选参数,如果指定了该参数,则返回指定类中的静态属性数组。
如果没有指定$name
参数,则返回当前类的所有静态属性数组;如果指定了$name
参数,则返回指定类中的静态属性数组。
//定义一个测试类
class Test{
public static $name = 'bee';
public static $age = 18;
private static $job = 'Programmer';
}
//实例化ReflectionClass类
$objReflectionClass = new ReflectionClass('Test');
//获取静态属性列表
$staticProperties = $objReflectionClass->getStaticProperties();
print_r($staticProperties);
/*
Array
(
[name] => bee
[age] => 18
)
*/
//获取指定类中的静态属性
$job = $objReflectionClass->getStaticProperties('job');
var_dump($job);//NULL,因为job是私有的,不能直接访问
Reflection
扩展。ReflectionClass setStaticPropertyValue()
函数实现。