Getting the default value for a property using php reflection

I am looking for a way to access the default assignment of a property without instantiating the class.

eg.

class Foo { private $bar = 'bar'; } $reflClass = new ReflectionClass('Foo'); $reflProp = $reflClass->getProperty('bar'); 

Now what? If I use $reflProp->getValue() (without an object argument), this will not work.

+4
source share
1 answer

You can use getDefaultProperties() :

 var_dump($reflClass->getDefaultProperties()); 
+5
source

Source: https://habr.com/ru/post/1332673/


All Articles