Pregunta

Here are three methods function_one, function_two and function_three in Example class.

class Example
{
    private function function_one() { ... }

    protected function function_two() { ... }

    public function function_three() { ... }

    public function check_here()
    {
        if (is_public_method('function_three')) {
            return true;
        } else {
            return false;
        }
    }
}

So, I want to know which Access Modifier (public, protected, private) is the method. The imaginary is_public_method should return true because function_three is public method. Is there way to do this?

¿Fue útil?

Solución

You can do this using ReflectionClass and ReflectionMethod:

public function check_here()
{
    $obj = new ReflectionClass($this);
    return $obj->getMethod('function_three')->isPublic();
}

Otros consejos

You need to be looking at ReflectionMethod's isPublic method.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top