PHP-Parser
PHP-Parser copied to clipboard
Find a root class of a class
Hi,
I need to find the root class of a class.
I tried to use AI, but the code does not work.
class BaseClass {}
class Parent extends BaseClass {}
class Child extends Parent {}
I would need something like:
$root = findRoot('Child'); // It should return "BaseClass"
You can either use php-src builtin reflection https://www.php.net/manual/en/reflectionclass.getparentclass.php
or https://github.com/Roave/BetterReflection in case you do not want to load/execute code