Reputation: 3448
Suppose I have the class:
class MyClass {
protected $protected;
private $_private;
public function __get($name) {
return $this->{$name};
}
}
I want to "magically" get protected variables but not private variables. Is there a built-in PHP function that will help me identify the visibility of a class variable?
Upvotes: 1
Views: 83
Reputation: 131891
$refClass = new ReflectionClass('MyClass');
foreach ($refClass->getProperties() as $property) {
if ($property->isProtected()) echo $property->getName();
}
Upvotes: 2