3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_cc() { $calls = debug_backtrace(); if (!isset($calls[1])) { return NULL; } $call = $calls[1]; var_dump($call); if (isset($call['object'])) { return get_class($call['object']); } elseif (isset($call['class'])) { return $call['class']; } } class Bar { public function bar() { return get_cc(); } public static function baz() { return get_cc(); } } class Foo extends Bar { } $bar = new Bar; echo ($bar->bar() === 'Bar' ? 'OK' : 'FAIL'), "\n<br>"; echo (Bar::baz() === 'Bar' ? 'OK' : 'FAIL'), "\n<br>"; $foo = new Foo; echo ($foo->bar() === 'Foo' ? 'OK' : 'FAIL'), "\n<br>"; echo (Foo::baz() === 'Foo' ? 'OK' : 'FAIL'), "\n<br>"; echo (get_cc() === NULL ? 'OK' : 'FAIL'), "\n<br>";

preferences:
25.78 ms | 402 KiB | 5 Q