Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting default value of property using php reflection

Tags:

php

reflection

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.

like image 849
Jake Avatar asked Dec 19 '10 16:12

Jake


1 Answers

You can use getDefaultProperties():

var_dump($reflClass->getDefaultProperties());
like image 113
István Ujj-Mészáros Avatar answered Oct 23 '22 18:10

István Ujj-Mészáros