Bug #67569 [NEW]: Make Closures serializable

From: Date: Fri, 04 Jul 2014 10:24:44 +0000
Subject: Bug #67569 [NEW]: Make Closures serializable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186467@lists.php.net to get a copy of this message
From: tom at r dot je Operating system: * PHP version: 5.5.14 Package: Class/Object related Bug Type: Bug Bug description:Make Closures serializable Description: ------------ This seems like a very arbitrary restriction from the PHP Developers. I don't know much about the internals of how they work, but serialzing variables used in the use() part is no different than storing instance variables inside objects so that shouldn't pose an issue. The issue, I'm guessing, is the method body. As it's not in a file it cannot be loaded if the variables are serialized, but since a Closure object is an internal class, why can't PHP store the method body in the closure object itself as an instance variable? Then the Closure object could be serialized and when unserialized, essentially just eval the method body to restore it? The closure class would then have a structure something like this: class Closure { private $body; private $args = []; private $bodyText; public function __invoke(...$args) { $this->body(...$args); } public function __wakeUp() { $this->body = eval($this->bodyText); } } -- Edit bug report at https://bugs.php.net/bug.php?id=67569&edit=1 --

« previous php.bugs (#186467) next »