ZF-7646: don't use "create_function" if possible

Description

Comments

Use a real function instead because: - the function byte code can't cache by apc and others - the return value is only a link the the function after removing this you can't call the function but it is in memory. (This seduce developers to to create a function on each function call like preg_match_callback)


var_dump(memory_get_usage(true));
for ($i=0; $i<1000; $i++) {
    create_function('$arg', '$test = "test";');
}
var_dump(memory_get_usage(true));
for ($i=0; $i<1000; $i++) {
    // same as above but allocates 3x more memory.
    create_function('$arg', '$test = "test";'
                          . '$test = "test";'
                          . '$test = "test";');
}
var_dump(memory_get_usage(true));

{panel:title=Used locations}

grep -iHrn 'create_function' * | grep -v 'svn'

libraries/framework.zend.com/Zend/Dom/Query/Css2Xpath.php:104: create_function( libraries/framework.zend.com/Zend/Dom/Query/Css2Xpath.php:116: create_function( libraries/framework.zend.com/Zend/Dom/Query/Css2Xpath.php:128: create_function( libraries/framework.zend.com/Zend/Feed/Element.php:170: return array_map(create_function('$e', 'return new Zend_Feed_Element($e);'), $nodes); {panel}

The places where create_function() are used are (a) not used for many situations, and (b) appropriate use cases. When we move to PHP 5.3 as the minimum supported version, these will be replaced with closures, but until then, there is no reason to change.