class Person { public $name = "John"; private $age = 30; } $reflection = new ReflectionProperty("Person", "name"); echo $reflection->getName(); // Output: name
class Person { public $name = "John"; private $age = 30; } $reflection = new ReflectionClass("Person"); $properties = $reflection->getProperties(); foreach ($properties as $property) { echo $property->getName() . "\n"; }This example creates a new ReflectionClass object for the "Person" class and retrieves all its properties using the `getProperties` method. It then loops through the properties and outputs their names using the `getName` method. Package/library: PHP Standard Library.