title: Serializing anonymous functions in php
body: <p>is there any way to serialize an anonymous function in php?</p>
  
  <p>i have found this <a href="http://www.htmlist.com/development/extending-php-5-3-closures-with-serialization-and-reflection/" rel="noreferrer">http://www.htmlist.com/development/extending-php-5-3-closures-with-serialization-and-reflection/</a></p>
  
  <pre><code>protected function _fetchCode()
  {
      // Open file and seek to the first line of the closure
      $file = new SplFileObject($this-&gt;reflection-&gt;getFileName());
      $file-&gt;seek($this-&gt;reflection-&gt;getStartLine()-1);
  
      // Retrieve all of the lines that contain code for the closure
      $code = '';
      while ($file-&gt;key() &lt; $this-&gt;reflection-&gt;getEndLine())
      {
          $code .= $file-&gt;current();
          $file-&gt;next();
      }
  
      // Only keep the code defining that closure
      $begin = strpos($code, 'function');
      $end = strrpos($code, '}');
      $code = substr($code, $begin, $end - $begin + 1);
  
      return $code;
  }
  </code></pre>
  
  <p>but it depends on the internal implementation of closure.</p>
  
  <p>are there any future plans to implement closure serialization?</p>