Issues

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

Issue Type: Sub-task Created: 2009-08-20T05:56:04.000+0000 Last Updated: 2009-08-20T06:10:31.000+0000 Status: Resolved Fix version(s): Reporter: Marc Bennewitz (GIATA mbH) (mben) Assignee: Matthew Weier O'Phinney (matthew) Tags: Related issues: Attachments:

Description

Comments

Posted by Marc Bennewitz (GIATA mbH) (mben) on 2009-08-20T06:05:01.000+0000

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)

<pre class="highlight">
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}

Posted by Matthew Weier O'Phinney (matthew) on 2009-08-20T06:06:43.000+0000

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts