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

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 foo {
      function foo() {
         // implements some logic
      }
      
      function name() {
         echo "My name is " , get_class($this) , "\n";
      }
   }
	
   // create an object
   $bar = new foo();
   
   // external call
   echo "Its name is " , get_class($bar) , "\n";
   
   // internal call
   $bar->name();
?> 

It will produce the following result −

Its name is foo
My name is foo

php_function_reference.htm