Skip to content

Instantly share code, notes, and snippets.

@khamer
Created January 20, 2011 20:20
Show Gist options
  • Select an option

  • Save khamer/788576 to your computer and use it in GitHub Desktop.

Select an option

Save khamer/788576 to your computer and use it in GitHub Desktop.
is_accessible() - function to check whether a property or method is accessible
<?php
function is_accessible($object, $prop) {
$rc_object = new ReflectionClass($object);
if ($rc_object->hasProperty($prop)) {
return $rc_object->getProperty($prop)->isPublic();
} elseif ($rc_object->hasMethod($prop)) {
return $rc_object->getMethod($prop)->isPublic();
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment