You must use ReflectionMethod. You can use isProtected and isPublic , as well as getModifiers
http://www.php.net/manual/en/class.reflectionmethod.php http://www.php.net/manual/en/reflectionmethod.getmodifiers.php
$rm = new ReflectionMethod($this, $method); //first argument can be string name of class or an instance of it. i had get_class here before but its unnecessary $isPublic = $rm->isPublic(); $isProtected = $rm->isProtected(); $modifierInt = $rm->getModifiers(); $isPublic2 = $modifierInt & 256; $isProtected2 = $modifierInt & 512;
As for checking whether a method exists or not, you can do it, as now, using method_exists or just try to build a ReflectionMethod, and an exception will be thrown if it does not exist. ReflectionClass has a getMethods function to get an array of all class methods if you want to use this.
Disclaimer - I don't know PHP Reflection too well, and there may be a more direct way to do this with ReflectionClass or something else
source share