3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_calling_scope() { $trace = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT); array_shift($trace); // Remove current frame $frame = array_shift($trace); if ($frame === null) { return null; } $function = $frame['function']; if (!in_array($function, ['__get', '__set', '__isset', '__unset', '__call', '__callStatic'], true)) { return null; } $object = $frame['object'] ?? null; $property = $frame['args'][0]; foreach ($trace as $previousFrame) { $previousObject = $previousFrame['object'] ?? null; if ($previousFrame['function'] !== $function || $previousObject !== $object || $previousFrame['args'][0] !== $property) { return $previousObject !== null ? $previousObject::class : null; } } return 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.27, 8.3.29 - 8.3.30, 8.4.1 - 8.4.14, 8.4.16 - 8.4.17, 8.5.0 - 8.5.2
NULL string(3) "Foo" string(3) "Bar"
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.

preferences:
138.04 ms | 407 KiB | 5 Q