PHP - Function get_class()



get_class ( $object );

Definition and Usage

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


Parameter Description
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.


Following is the usage of this function −

   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

It will produce the following result −

Its name is foo
My name is foo