Serialize Closures in PHP using this neat package

1 · Amit Merchant · July 22, 2019, 6:18 p.m.
It’s widely known that PHP can’t serialize closures directly. If you try to serialize a closure in PHP, it will result in a fatal error. Take below for example. <?php $func = function () { echo 'hello!'; }; $func(); // prints "hello!" $result = serialize($func); // Fatal error: Uncaught exception 'Exception' // with message 'Serialization of 'Closure' is not allowed' ?> There are many ways to overcome this issue. One of which you can write your own implementation by using _sleep() and ...