3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo {} class Bar { public function firstTypeError ($passed) { $trace = debug_backtrace(); throw new TypeError(__CLASS__ . "::" . __FUNCTION__ . "(): Argument #1 (\$passed) elements must be of type " . Baz::class . ", " . get_debug_Type($passed) . " given, called in " . $trace[0]["file"] . " on line " . $trace[0]["line"]); } public function secondTypeError ($passed) { $trace = debug_backtrace(); throw new TypeError(__CLASS__ . "::" . __FUNCTION__ . "(): Argument #1 (\$passed) elements must be of type " . Baz::class . ", " . get_debug_Type($passed) . " given"); } } class Baz {} $bar = new Bar(); try { $bar->firstTypeError("test"); } catch (TypeError $e) { echo $e->__toString(); } echo "\n\n\n\n"; try { $bar->secondTypeError("test"); } catch (TypeError $e) { echo $e->__toString(); }

preferences:
28.99 ms | 405 KiB | 5 Q