class MyClass { public function method1(){} private function method2(){} protected function method3(){} } $reflection = new ReflectionClass('MyClass'); $methods = $reflection->getMethods(); foreach ($methods as $method) { echo $method->getName() . "\n"; }
function myFunction(){ echo "Hello World!"; } $reflection = new ReflectionFunction('myFunction'); $methods = $reflection->getMethods(); foreach ($methods as $method) { echo $method->getName() . "\n"; }This example defines a simple function myFunction and creates a new ReflectionFunction object for that function. The getMethods method is called on this object to retrieve an array of all the methods of myFunction. Finally, a loop iterates through this array and prints the name of each method. The package library for this code is the PHP Reflection API.