PHP get_class() function

Description

get_class() returns the class name of the object you pass to it.

Syntax

string get_class ([ object $object = NULL ] )

Parameters

  • object - The tested object. This parameter may be omitted when inside a class.

Return Values

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

If object is omitted when inside a class, the name of that class is returned.

Example

Get the class name


<?php/* www .  j  av a2s .  c o m*/

class foo {
    function name()
    {
        echo "My name is " , get_class($this) , "\n";
    }
}

$bar = new foo();
echo "Its name is " , get_class($bar) , "\n";
$bar->name();

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions