class MyClass { /** * This is a property. * * @var string */ protected $myProperty; } $reflectionClass = new ReflectionClass('MyClass'); $reflectionProperty = $reflectionClass->getProperty('myProperty'); $docComment = $reflectionProperty->getDocComment(); echo $docComment;
/** * This is a property. * * @var string */
/** * @package MyPackage */ class MyClass { /** * This is a property. * * @var string */ protected $myProperty; } $reflectionClass = new ReflectionClass('MyClass'); $reflectionProperty = $reflectionClass->getProperty('myProperty'); $docComment = $reflectionProperty->getDocComment(); if (strpos($docComment, '@package') !== false) { preg_match('/@package\s+([\w\\\]+)/', $docComment, $matches); echo $matches[1]; }
MyPackageThis example demonstrates how the `getDocComment` method can be used to extract additional information from a property's documentation comment.