3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_calling_scope() { return debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]['class'] ?? null; } class Foo { public function __get($name) { var_dump(get_calling_scope()); return ''; } public function test() { $this->bar; } } class Bar extends Foo { public function __get($name) { parent::__get($name); return ''; } } $foo = new Foo(); $foo->bar; $foo->test(); $bar = new Bar(); $bar->test();
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
NULL string(3) "Foo" string(3) "Bar"

preferences:
82.46 ms | 1114 KiB | 4 Q