Serializing anonymous functions in php

Is there a way to serialize an anonymous function in php?

I found this http://www.htmlist.com/development/extending-php-5-3-closures-with-serialization-and-reflection/

protected function _fetchCode() { // Open file and seek to the first line of the closure $file = new SplFileObject($this->reflection->getFileName()); $file->seek($this->reflection->getStartLine()-1); // Retrieve all of the lines that contain code for the closure $code = ''; while ($file->key() < $this->reflection->getEndLine()) { $code .= $file->current(); $file->next(); } // Only keep the code defining that closure $begin = strpos($code, 'function'); $end = strrpos($code, '}'); $code = substr($code, $begin, $end - $begin + 1); return $code; } 

but it depends on the internal implementation of the closure.

Are there any future plans for implementing closure serialization?

+6
source share
1 answer

Take a look at my answer here about PHP Super Closure:

Exception: Closing serialization is not allowed.

Hope this helps.

+3
source

Source: https://habr.com/ru/post/944943/


All Articles