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?
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?
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
)
)
Or you can do this:
$getPublicProperties = create_function('$object', 'return get_object_vars($object);'); var_dump($getPublicProperties($this));