Code can get complex. Inheritance and variable variables can lead to confusion. Sometimes it’s nice just to know what happened where. That’s were these magic constants come in handy most often and here’s another one.

The constant __CLASS__ will give you the name of the class it’s in. The case is preserved. It works anywhere in the class.

class Monkey_Test {
  const class_name = __CLASS__;
 
  public function monKey() {
    return "I'm in: " . __CLASS__;
  }
 
  static public function butLer() {
    return "I'm in: " . __CLASS__;
  }
}
 
echo Monkey_Test::class_name; // Monkey_Test
echo Monkey_Test::butLer();   // I'm in: Monkey_Test
$m = new Monkey_Test();
echo $m->monKey();            // I'm in: Monkey_Test