• PHP Video Tutorials

PHP - Function get_parent_class()



Syntax

get_parent_class ( $object );

Definition and Usage

It retrieves the parent class name for object or class.

Parameters

Sr.No Parameter & Description
1

object(Required)

The tested object or class name.

Return Value

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

Example

Following is the usage of this function −

<?php
   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();
?> 

It will produce the following result −

I'm f1's son
I'm f1's son too
php_function_reference.htm
Advertisements