The get_parent_class Function

The get_parent_class function returns the name of the parent class for the specified object or class. If no parent class exists, the function returns false. You can pass either an object or a class name as a string as a parameter.

Syntax

phpget_parent_class(object|string);

Example

Get the parent class for an object:

php<?php
  class ParentClass {}
  class ChildClass extends ParentClass {}
  
  $obj = new ChildClass();
  echo get_parent_class($obj);
?>

Execution result:

php'ParentClass'

Example

Get the parent class by the class name:

php<?php
  class ParentClass {}
  class ChildClass extends ParentClass {}
  
  echo get_parent_class('ChildClass');
?>

Execution result:

php'ParentClass'

Example

Try to get the parent class for a class without a parent:

php<?php
  class SimpleClass {}
  
  var_dump(get_parent_class('SimpleClass'));
?>

Execution result:

phpfalse

See Also