PHP | get_parent_class() Function

PHP get_parent_class() Function

Hello dear readers! welcome back to another edition of our tutorial on PHP. In this tutorial guide, we are going to be discussing about the PHP get_parent_class() Function.

The get_parent_class() Function gets the parent class name for the object or class.


Following below is the syntax to use this function -

get_parent_class ( $object );

RECOMMENDED POST: PHP | easter_date() Function

Parameter Details

Sr.NoParameter & Description


The tested object or class name.

Return Value

It returns an array of the names of the declared classes in the current script.


Try out the below example -

   class f1 {
      function f1() {
         // implements some logic
   class child extends f1 {
      function child() {
         echo "I'm " , get_parent_class($this) , "'s son \n";
   class child2 extends f1 {
      function child2() {
         echo "I'm " , get_parent_class('child2') , "'s son too \n";
   $foo = new child();
   $bar = new child2();


When the above code is executed, it will produce the following result -

I'm f1's son
I'm f1's son too

Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the PHP interface_exists() Function.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.