class Example { public function publicMethod() { echo "This is a public method"; } protected function protectedMethod() { echo "This is a protected method"; } private function privateMethod() { echo "This is a private method"; } } $example = new Example(); $reflectionMethod = new ReflectionMethod('Example', 'publicMethod'); var_dump($reflectionMethod->isPublic()); // Output: bool(true) $reflectionMethod = new ReflectionMethod('Example', 'protectedMethod'); var_dump($reflectionMethod->isPublic()); // Output: bool(false) $reflectionMethod = new ReflectionMethod('Example', 'privateMethod'); var_dump($reflectionMethod->isPublic()); // Output: bool(false)
class Example { public function publicMethod1() { echo "This is public method 1"; } public function publicMethod2() { echo "This is public method 2"; } protected function protectedMethod() { echo "This is a protected method"; } } $example = new Example(); $reflectionClass = new ReflectionClass($example); foreach($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { echo $method->name."\n"; } // Output: publicMethod1 publicMethod2Package library: This functionality is a part of the core PHP library and does not require any additional package.