3

Is there a better/shorter way to write the whoAmI method in the following code? It seems a bit unnecessary to create a new object just to get the static class' name.

<?php

abstract class baseClass {
    static function whoAmI() {
        echo get_class(new static); // Making a new class just to get its name???
    }
}
too much php
  • 88,666
  • 34
  • 128
  • 138
  • I love that you use such a verbose way of finding the static class' name, and have the username 'too much php' =) Good question though, I hadn't come across `get_called_class()` before (from the accepted answer, from Erlend). – David Thomas Nov 08 '09 at 19:36

1 Answers1

9

Try get_called_class().

http://php.net/manual/en/function.get-called-class.php

klakegg
  • 181
  • 1
  • 8