class MyClass { public function myMethod() { // function body } } $reflection = new ReflectionObject(new MyClass()); $method = $reflection->getMethod('myMethod');
class MyClass { public function myMethod1() {} protected function myMethod2() {} private function myMethod3() {} } $reflection = new ReflectionObject(new MyClass()); $methods = $reflection->getMethods(); foreach ($methods as $method) { echo $method->getName() . PHP_EOL; }In this example, a ReflectionObject is created for the MyClass class, and then the getMethods() method is called to get a list of all methods in the class. The foreach loop is used to iterate over the list of methods, and the getName() method is called on each method to print out its name. Package/library: The ReflectionObject class is part of the PHP core language and is not a part of any package or library.