3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public int $v; public function makeClosure(int $v) { return function () use ($v) { echo $this->v . '-' . $v . "\n"; throw new \Exception(); }; } } $foo = new Foo(); $foo->v = 2; $fx = $foo->makeClosure(3); try { $fx(); } catch (\Throwable $e) { print_r($e); }
Output for 8.4.1 - 8.4.15, 8.5.0
2-3 Exception Object ( [message:protected] => [string:Exception:private] => [code:protected] => 0 [file:protected] => /in/YqFcG [line:protected] => 10 [trace:Exception:private] => Array ( [0] => Array ( [file] => /in/YqFcG [line] => 20 [function] => {closure:Foo::makeClosure():8} [class] => Foo [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => )
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28
2-3 Exception Object ( [message:protected] => [string:Exception:private] => [code:protected] => 0 [file:protected] => /in/YqFcG [line:protected] => 10 [trace:Exception:private] => Array ( [0] => Array ( [file] => /in/YqFcG [line] => 20 [function] => {closure} [class] => Foo [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => )

preferences:
48.45 ms | 409 KiB | 5 Q