class User { /** * Check if the user is valid * * @param int $id User ID * @return bool True if user is valid, false otherwise */ public function isValid($id) { // Implementation } } $method = new ReflectionMethod('User', 'isValid'); $comment = $method->getDocComment(); echo $comment;
function getMethodDocs($className) { $class = new ReflectionClass($className); $methods = $class->getMethods(); foreach ($methods as $method) { $comment = $method->getDocComment(); echo $comment; } } getMethodDocs("User");Package library: PHP Reflection API