6

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->getProperty('bar');

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

1 Answer 1

9

You can use getDefaultProperties():

var_dump($reflClass->getDefaultProperties());
Sign up to request clarification or add additional context in comments.

1 Comment

+1 Very, very nice. I can hear the reflection API screaming to be documented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.