PHP's backtrace structure includes a reference to the object whose method is being called at each level of the stack. When it tries to serialize the trace, any objects which reference closures (or reference objects which themselves reference closures and so on) will prevent serialization.
In your case, you can re-cast the trace into a slightly less descriptive form or find which objects contain closures and either repackage the closures as __invoke
instances or skip them when serializing by implementing Serializable
, as described here. Your choice here would depend on what you're doing with the trace. If it's only meant to a be human-readable description of what went wrong, consider using the getTraceAsString()
method instead of getTrace()
.