3v4l.org

run code in 300+ PHP versions simultaneously
<?php function dump(...$values): void { foreach ($values as $value) { echo json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL; } } class Foo { public readonly Exception $e; public function __construct() { $this->e = new Exception; dump(debug_backtrace()); } } class Bar extends Foo { public function __construct() { parent::__construct(); } } function Bar(): Bar { return new Bar(); } $bar = new Bar(); dump($bar->e->getTrace());
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.5 - 8.3.26, 8.4.1 - 8.4.13
[ { "file": "/in/QjBWV", "line": 24, "function": "__construct", "class": "Foo", "object": { "e": {} }, "type": "->", "args": [] }, { "file": "/in/QjBWV", "line": 33, "function": "__construct", "class": "Bar", "object": { "e": {} }, "type": "->", "args": [] } ] [ { "file": "/in/QjBWV", "line": 24, "function": "__construct", "class": "Foo", "type": "->", "args": [] }, { "file": "/in/QjBWV", "line": 33, "function": "__construct", "class": "Bar", "type": "->", "args": [] } ]
Output for 8.0.1 - 8.0.28
Parse error: syntax error, unexpected identifier "Exception", expecting variable in /in/QjBWV on line 12
Process exited with code 255.

preferences:
72.21 ms | 407 KiB | 5 Q