English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP reference manual

PHP get_class() function usage and example

PHP Class/Object function reference manual

The get_class() function returns the class name of the object

Syntax

get_class ( $object );

Definition and usage

This function gets the class name of the given object.

Parameter

Serial numberParameters and description
1

object(Required)

The object to be tested. This parameter can be omitted if it is in the class.

Return value

It returns the name of the class of the object. If the object is not an object, it returns FALSE.

Online example

The following is the usage of this function, returning the name of the instance object-

<?php
   class f1 {
      function f1() {
         // Implement 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();
?>
Test and see‹/›

It will produce the following result-

Its name is f1
My name is  f1

 PHP Class/Object function reference manual