How to get public properties of a class?
class, php, properties, public
Solution
This is possible by using reflection.
<?php
class Foo {
public $alpha = 1;
protected $beta = 2;
private $gamma = 3;
}
$ref = new ReflectionClass('Foo');
print_r($ref->getProperties(ReflectionProperty::IS_PUBLIC));
the result is:
Array
(
[0] => ReflectionProperty Object
(
[name] => alpha
[class] => Foo
)
)
Problem
I can't use simply `get_class_vars()` because I need it to work with PHP version earlier than 5.0.3 (see http://pl.php.net/get_class_vars Changelog) Alternatively: How can I check if property is public?