In the latest Zend Framework 2.0, a large number of php5.3 closure features have been introduced. You can initialize a module by introducing a closure in the configuration file. (See: Http://packages.zendframework.com/doc ... )
However, the configuration file will have a cache, format conversion and other requirements (PHP = XML), at this time in the configuration file of the closure should be handled? Direct serialization of closed PHP is not supported.
Reply content:
In the latest Zend Framework 2.0, a large number of php5.3 closure features have been introduced. You can initialize a module by introducing a closure in the configuration file. (See: Http://packages.zendframework.com/doc ... )
However, the configuration file will have a cache, format conversion and other requirements (PHP = XML), at this time in the configuration file of the closure should be handled? Direct serialization of closed PHP is not supported.
Never used Zend, but I think ZF2 is just simple to copy the closure function code to a different format of the configuration file, the final is to re-write back to the PHP code format of the cache (can run directly), otherwise the runtime to parse the configuration file, the efficiency is poor.
You really need to serialize, you can use reflection (Reflection), and directly manipulate the code file to get contextual information:
/** * Create a reflection: */$reflection = new Reflectionfunction ($closure),/** * parameters can be directly obtained: */$params = $reflection->getparameters ();/** * Obtains the function body and the use variable of closure, such as: * Function ($arg 1, $arg 2, ...) use ($val 1, $val 2, ...) {* //To get the code for this section! *} * Many ways, you can directly use regular, string lookup or Tokenizer, and so on. * For example, you can get the start and end lines of the function from reflection first: */$startLine = $reflection->getstartline (); $endLine = $reflection->getendline ();//Then use str* this, str* that function to clean up, the details do not write: $usedVars = use variables; $closureBody = function body;//...
At this point params,usedvars,closurebody and so on are just arrays and strings.