开发者

Getting default value of property using php reflection

开发者 https://www.devze.com 2023-01-31 03:31 出处:网络
I\'m looking for a way to access the default value assignment for a property without instantiating the class.

I'm looking for a way to access the default value assignment for a property without instantiating the class.

E.g.

class Foo {
   private $bar = 'bar';
}

$reflClass = new ReflectionClass('Foo');
$reflProp = $reflClass-开发者_如何学JAVA>getProperty('bar');

Now what? If I use $reflProp->getValue() (without an object argument) it will fail.


You can use getDefaultProperties():

var_dump($reflClass->getDefaultProperties());
0

精彩评论

暂无评论...
验证码 换一张
取 消