Is it possible to serialize closures in PHP?

Asked

Viewed 63 times

1

It is possible to serialize closures in PHP (even if it is not natively)?

Because PHP generates a Fatal Error while trying to do so:

$func = function ($a, $b)
{   
     return $a + $b;
};

serialize($func);

This generates:

Exception: Serialization of 'Closure' is not allowed

  • Related (Soen): http://stackoverflow.com/a/19730234/2256325

  • Useful: http://www.htmlist.com/development/extending-php-5-3-closures-with-serialization-and-reflection/

1 answer

2


I believe you are bringing content from the OS here. So just do what you already was answered there. The function serialize() It’s not gonna work anyway, she’s not ready for this.

There is another solution posted there that should help better what you want, is the use of the library Super Closure that uses reflection to achieve the goal. If you want to do something on your own, the best way is to analyze what this library does.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.