In the latest ZendFramework2.0, the closure feature of php5.3 has been widely used. You can introduce a closure in the configuration file to initialize the module. (See packages. zendframework. comdoc ...) however, the configuration file will have cache and format conversion requirements (p... in the latest Zend Framework 2.0, the closure feature of php5.3 has been widely used. You can introduce a closure in the configuration file to initialize the module. (See: http://packages.zendframework.com/doc ...)
However, the configuration file will have cache, format conversion, and other requirements (php => xml). What should I do with the closure in the configuration file? Php does not support directly serializing closures.
Reply content:
In the latest Zend Framework 2.0, the closure feature of php5.3 has been widely used. You can introduce a closure in the configuration file to initialize the module. (See: http://packages.zendframework.com/doc ...)
However, the configuration file will have cache, format conversion, and other requirements (php => xml). What should I do with the closure in the configuration file? Php does not support directly serializing closures.
Zend has never been used, but I think ZF2 simply copies the code of the closure function to the configuration files in different formats, in the end, it must be written back to the PHP code format cache (which can be run directly). Otherwise, the configuration file will be parsed during the runtime, which is too inefficient.
Serialization is required. You can use Reflection and directly operate the code file to obtain the context information:
/*** Create a reflection: */$ reflection = new ReflectionFunction ($ closure);/*** the parameter can be directly obtained: */$ params = $ reflection-> getParameters ();/*** obtain the Closure function body and use variables, for example, * function ($ arg1, $ arg2 ,...) use ($ val1, $ val2 ,...) {* // obtain the code for this part! *} * There are many methods. You can use regular expressions, string searches, Tokenizer, and so on. * For example, you can first obtain the start and end rows of the function from reflection: */$ startLine = $ reflection-> getStartLine (); $ endLine = $ reflection-> getEndLine (); // use the str * And str * functions to clear the data. The details are not written: $ usedVars = use variables; $ closureBody = function body ;//...
Now params, usedVars, closureBody, and so on are just arrays and strings.