class Car { public $model; public function drive() { echo "Driving a car."; } } $reflect = new ReflectionClass('Car'); echo $reflect->getName(); // output: Car
$object = new Car(); $reflect = new ReflectionClass($object); echo $reflect->getName(); // output: CarIn this example, we instantiate a new Car object and create its reflection using the ReflectionClass constructor that accepts an object as a parameter. Then, we call getName() method to retrieve the Car class name. These examples do not use any package library, they demonstrate the basic functionality of the ReflectionClass class that is part of the PHP core.