PHP - Function get_class()


Advertisements


Syntax

get_class ( $object );

Definition and Usage

This function gets the name of the class of the given object.

Parameters

Sr.No Parameter & Description
1

object(Required)

The tested object.

Return Value

It returns the name of the class of which object is an instance. Returns FALSE if object is not an object.

Example

Following is the usage of this function −

<?php
   class f1 {
      function f1() {
         // implements some logic
      }
      
      function name() {
         echo "My name is " , get_class($this) , "\n";
      }
   }
	
   // create an object
   $bar = new f1();
   
   // external call
   echo "Its name is " , get_class($bar) , "\n";
   
   // internal call
   $bar->name();
?> 

It will produce the following result −

Its name is f1
My name is f1

php_function_reference.htm