'Is there a PHP equivalent of Python's traceback.format_exc()?

In python, if an exception is thrown, you can call traceback.format_exc() to get a complete stack trace of the exception as a string that can be stored in a variable, as if you were debugging.

In PHP, I do have access to the exception message via catch (Exception $e), but I was wondering if there were a way to get the stack trace of the line that threw the exception, as a string?

Specifically PHP 7.3 would be helpful, as this is the version of our interpreter.



Solution 1:[1]

I think debug_backtrace() will do the same in PHP

https://www.php.net/manual/en/function.debug-backtrace.php

I hope it's helpful

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ahmed Hassan