3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ExceptionFixer { public static function throw(self $exception): self { $exception->file = $exception->getTrace()[0]['file']; $exception->line = $exception->getTrace()[0]['line']; return $exception; } } class MyException extends Exception { use ExceptionFixer; public static function create(): self { return self::throw(new MyException('Custom exception')); } } try { throw MyException::create(); } catch (Exception $exception) { echo $exception->getLine() . PHP_EOL; }
based on HlZDW
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 - 7.4.10, 8.0.0alpha1 - beta3
16