Skip to content

Instantly share code, notes, and snippets.

View nh-mike's full-sized avatar
🤘
It works on my machine, must be something wrong on yours

Michael Thompson nh-mike

🤘
It works on my machine, must be something wrong on yours
View GitHub Profile
@nh-mike
nh-mike / flattenExceptionBacktrace.php
Last active July 4, 2021 10:44 — forked from Thinkscape/flattenExceptionBacktrace.php
Make any PHP Exception serializable by flattening complex values in backtrace.
<?php
function flattenExceptionBacktrace(\Throwable $exception) {
if ($exception instanceof \Exception) {
$traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace');
} else {
$traceProperty = (new \ReflectionClass('Error'))->getProperty('trace');
}
$traceProperty->setAccessible(true);
$flatten = function(&$value, $key) {