Get the name of the class of an object in PHP

Description

The following code shows how to get the name of the class of an object.

Example


/*ww w. j av a 2 s.  c  o  m*/
//Using get_class() in superclass
<?php

abstract class bar {
    public function __construct()
    {
        var_dump(get_class($this));
        var_dump(get_class());
    }
}

class foo extends bar {
}

new foo;

?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Development »




Environment
Error
Hash
Include
Locale
Math
Network
Output
Reflection
PHP Regular Expressions