class ExampleClass { /** * This is an example description for ExampleClass. * * @return void */ public function exampleMethod() { // Method code ... } } $reflection = new ReflectionClass('ExampleClass'); $docComment = $reflection->getDocComment(); // Outputs "/**\n * This is an example description for ExampleClass.\n *\n * @return void\n */"
namespace ExamplePackage\ExampleNamespace; /** * This class is an example class for ExamplePackage. */ class ExampleClass { /** * This is an example method for ExampleClass. * * @return void */ public function exampleMethod() { // Method code ... } } $reflection = new ReflectionClass('ExamplePackage\ExampleNamespace\ExampleClass'); $docComment = $reflection->getDocComment(); // Outputs "/**\n * This class is an example class for ExamplePackage.\n */"In the above example, we create a class `ExampleClass` inside the namespace `ExamplePackage\ExampleNamespace` with a PHPDoc comment. We then use the `ReflectionClass` API to retrieve the class by its fully qualified name and call `getDocComment()` on it, which returns the PHPDoc comment for the class. Package/Library: The ReflectionClass is a part of PHP's core library and can be used without the need for any particular package or library.