Possible Duplicate:
Get class name from extended class
Suppose I have the following:
class Foo
{
public $name;
public __construct()
{
$this->name = __CLASS__;
}
}
class Bar extends Foo
{
}
class FooBar extends Foo
{
}
$bar = new Bar();
echo $bar->name; // will output 'Foo', but I want 'Bar'
$foobar = new FooBar();
echo $foobar->name; // will output 'Foo', but I want 'FooBar'
Is there a way to get the name of the constructing class, without setting the name in a extended class e.g. setting the name in class Foo?
Note: I have a lot of classed derived from Foo, setting the name in every derived class would be a lot of coding.
http://php.net/get_class