How to get all private var names from a class in PHP?
php
Solution
I would suggest using PHP's ReflectionClass. In particular the `getProperties()` call.
Here is the PHP documentation:
http://www.php.net/manual/en/reflectionclass.getproperties.php
As sample would be:
class A
{
function getvars()
{
$reflection = new ReflectionClass($this);
$vars = $reflection->getProperties(ReflectionProperty::IS_PRIVATE);
var_dump($vars);
}
}
class B extends A
{
private $name;
}
Also note that you can change the filter on getProperties methods or omit it altogether (here I have shown the filter for private only).
Problem
`get_class_vars` gets all public vars, but I want to access private ones. I am doing it from a parent class, trying to get the child class vars... ``` class A { function getvars() { /* get private vars from child */ } } class B extends A { private $name; } ``` Is there another method to do this?