Tutorials Point


  Learning PHP
  Advanced PHP
  PHP Function Reference
  PHP Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

PHP Function get_class()


previous

Advertisements

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

previous Printer Friendly

Advertisements


  

Advertisements