Reputation: 3857
Is any way to check method type in php if it is public, private or protected?
what I tried: I have class and it have methods I can put this methods in url and grt pages so I need a way if the users put the private methods in url then the user get an error page such as "Access denied"
Ex:
if (method_type ('Get_user') == 'private'){
header ("location: ./")
}
Upvotes: 2
Views: 2036
Reputation: 109
You could try using ReflectionMethod, check the following link for more info on it: http://php.net/manual/en/class.reflectionmethod.php
Also you might try to use is_callable but that relates to scope so it will yield a different result depending on the class you're in. You can check it out here: http://www.php.net/manual/en/function.is-callable.php
Upvotes: 0
Reputation: 3844
try this,
$check = new ReflectionMethod('class', 'method');
if($check->isPublic()){
echo "public";
} elseif($check->isPrivate()){
echo "private";
} else{
echo "protected";
}
Upvotes: 1
Reputation: 870
Simply use ReflectionMethods Check Link http://www.php.net/manual/en/class.reflectionmethod.php
$reflection = new ReflectionMethod('className', $functionName);
if ($reflection->isPublic()) {
echo "Public method";
}
if ($reflection->isPrivate()) {
echo "Private method";
}
if ($reflection->isProtected()) {
echo "Protected method";
}
Upvotes: 4
Reputation: 100195
you could use Reflection class, such as ReflectionMethod::isPrivate
Upvotes: 0