Serialization of an Exception is not possible inside the closure
borys-p opened this issue · 1 comments
Serializable Closure Version
1.3.1
PHP Version
8.2.8
Description
Serialization of an Exception
inside the serializable closure results with the Serialization of 'Closure' is not allowed
exception. This is most likely caused by an attempt to serialize the stack trace, which contains the serializable closure itself, but this time without the ability to do its magic.
And, frankly, I'm not sure if there's anything that can be done about it, other than adding another warning to the documentation. You can't do much with an already existing Exception
object and its stack trace.
Steps To Reproduce
This issue is very easy to reproduce:
$closure = new \Laravel\SerializableClosure\SerializableClosure(function() { return serialize(new \Exception('boom')); });
echo $closure();
This works as expected:
$closure = function() { return serialize(new \Exception('boom')); };
echo $closure();
Hi there. I don't think it ever was intended to serialize an exception like this indeed. Can you send in a PR to the docs? Thanks!