<?php
class ExecutionFailureBuilder
{
public function build(\Throwable $execption): ExecutionFailureInterface
{
}
public static function flattenExceptionBacktrace(\Throwable $throwable)
{
$flatten = function(&$value, $key) {
if ($value instanceof \Closure) {
$closureReflection = new \ReflectionFunction($value);
$value = sprintf(
'(Closure at %s:%s)',
$closureReflection->getFileName(),
$closureReflection->getStartLine()
);
} elseif (is_object($value)) {
$value = sprintf('object(%s)', get_class($value));
} elseif (is_resource($value)) {
$value = sprintf('resource(%s)', get_resource_type($value));
}
};
do {
$trace = $throwable->getTrace();
foreach ($trace as &$call) {
array_walk_recursive($call['args'], $flatten);
}
var_dump($trace);
} while($throwable = $throwable->getPrevious());
}
}
$a = function($b, string $c) {
try {
throw new Exception();
} catch (Exception $e) {
ExecutionFailureBuilder::flattenExceptionBacktrace($e);
}
};
$b = new class(4, 'rfvtgb') {
public function __construct($b, string $c)
{
try {
throw new Exception();
} catch (Exception $e) {
ExecutionFailureBuilder::flattenExceptionBacktrace($e);
}
}
};
class Testing
{
public static function test($b, string $c)
{
try {
throw new Exception();
} catch (Exception $e) {
ExecutionFailureBuilder::flattenExceptionBacktrace($e);
}
}
};
$a(3, 'RTYuio', new \stdClass, []);
Testing::test(5, 'rfv');
preferences:
51.67 ms | 402 KiB | 5 Q