ReflectionClass::getParentClass

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getParentClassGets parent class

Description

public ReflectionClass::getParentClass(): ReflectionClass|false

Get the parent class.

Parameters

This function has no parameters.

Return Values

A ReflectionClass or false if there's no parent.

See Also

add a note

User Contributed Notes 1 note

up
18
isaac dot z dot foster at gmail dot com
11 years ago
To find all parents of a class you can use the following code:

$class = new ReflectionClass('classname');

$parents = [];

while ($parent = $class->getParentClass()) {
$parents[] = $parent->getName();
$class = $parent;
}

echo "Parents: " . implode(", ", $parents);
To Top

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant