Get class name from extended class

oop, php

Solution

Use:

get_class($this);

Problem

Is it possible to get the name of the top level class from an extended class, without setting it from the top level class. See example below, I would like to get 'Foo' from Base. I know I could set a variable from Foo, but hoping to skip the extra step. Thanks. ``` class Base { function __construct() { echo '<p>get_class: '.get_class().'</p>'; echo '<p>__CLASS__: '.__CLASS__.'</p>'; } } class Foo extends Base { } $test = new Foo(); ``` (PHP 5.2.4+)

Original source