class ParentClass {} class ChildClass extends ParentClass {} $child = new ReflectionClass('ChildClass'); $parent = $child->getParentClass(); if ($parent !== false) { echo $parent->getName(); // Output: ParentClass }
class MyClass {} $myClass = new ReflectionClass('MyClass'); $parent = $myClass->getParentClass(); if ($parent === false) { echo "This class has no parent class."; }This example creates a class `MyClass` and the `ReflectionClass` instance of the class is created. The `getParentClass` method returns false because the class has no parent class. The code then prints a message letting the user know that the class has no parent class. This method is a part of the PHP Reflection API library.