$userClass = new ReflectionClass('User'); $userNameProperty = $userClass->getProperty('name'); $propertyMetadata = $userNameProperty->getDocComment(); echo $propertyMetadata; // Output: "@var string The name of the user"
$productClass = new ReflectionClass('Product'); $properties = $productClass->getProperties(); foreach ($properties as $property) { echo $property->getName() . ': ' . $property->getDocComment() . "\n"; }In this example, we use the ReflectionClass getProperties method to retrieve an array of all properties in the "Product" class. Then we loop through each property and output its name and associated "doc comment". These examples are likely part of the Reflection API, which is a built-in PHP package/library.