Monday 26 August 2013

PHP Function get_class()

Syntax

get_class ( $object );

Definition and Usage

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

Paramters

ParameterDescription
objectRequired. 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) , "<br>";

// internal call
$bar->name();
?> 
It will produce following result:
Its name is foo
My name is foo

No comments:

Post a Comment