Is it possible to serialize closures in PHP? [duplicate]

1

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

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

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

serialize($func);

This generates:

  

Exception: Serialization of 'Closure' is not allowed

    
asked by anonymous 31.07.2015 / 17:16

1 answer

2

I think you're bringing OS content here. So just do what already was answered there . The serialize() function will not work at all, it is not ready for this.

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

    
31.07.2015 / 17:22