class Example { private $property1 = 1; protected $property2 = 2; public function method1() {} protected function method2() {} } $reflection = new ReflectionClass('Example'); echo $reflection->getName(); // Example $properties = $reflection->getProperties(); foreach ($properties as $property) { echo $property->getName(); // property1, property2 }
class Example { public function method1($param1, $param2) {} private function method2() {} } $reflection = new ReflectionClass('Example'); $methods = $reflection->getMethods(); foreach ($methods as $method) { echo $method->getName(); // method1, method2 $parameters = $method->getParameters(); foreach ($parameters as $parameter) { echo $parameter->getName(); // param1, param2 } }This example uses ReflectionClass to get the names of methods in a class and the names of their parameters. Package/library: ReflectionClass is a built-in class in the PHP language, part of the PHP Standard Library.