class Example { public function publicMethod() {} private function privateMethod() {} } $reflection = new ReflectionMethod('Example', 'publicMethod'); $modifiers = $reflection->getModifiers(); if ($modifiers & ReflectionMethod::IS_PUBLIC) { echo "The publicMethod is public"; } $reflection = new ReflectionMethod('Example', 'privateMethod'); $modifiers = $reflection->getModifiers(); if ($modifiers & ReflectionMethod::IS_PRIVATE) { echo "The privateMethod is private"; }
class Example { final public static function myMethod() {} } $reflection = new ReflectionMethod('Example', 'myMethod'); $modifiers = $reflection->getModifiers(); if ($modifiers & ReflectionMethod::IS_FINAL) { echo "The method is final"; } if ($modifiers & ReflectionMethod::IS_STATIC) { echo "The method is static"; }In this example, the reflection API is used to retrieve the final and static modifiers of a method in a class. The IS_FINAL and IS_STATIC constants are used to determine if the method is final or static, respectively. These examples use the reflection API in PHP, which is part of the core PHP package library.