Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65604 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56091 invoked from network); 4 Feb 2013 04:37:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2013 04:37:06 -0000 X-Host-Fingerprint: 195.42.115.214 de.p44.net Received: from [195.42.115.214] ([195.42.115.214:27122] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/00-55736-1FA3F015 for ; Sun, 03 Feb 2013 23:37:06 -0500 To: internals@lists.php.net,"Sebastian Bergmann" Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes References: <510E995C.3020802@php.net> <510E9F51.4000503@php.net> Date: Mon, 04 Feb 2013 11:36:59 +0700 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: User-Agent: Opera Mail/12.12 (Win32) X-Posted-By: 195.42.115.214 Subject: Re: [PHP-DEV] (non)growing memory while creating anoymous functions via eval() From: petrich@tronic-media.com ("Hans-Juergen Petrich") Hello > Then again, your code still does not make sense to me ... Fully understand :-) Not want wasting your time with my specific situation... but there are situation where it make sense :-) For example... in my situation, i have time intensive (mathematically) operations to do in pure php and was searching a way to speed this operations up. With PHP's eval() feature, creating php code at run time, this would be, in my situation, a possible way. Very simplified, i have to deal with the following: function calculate($ints) { $result = 0; for ($i=0; $i<10000000; ++$i) { $result += $ints[0] + $ints[1] + $ints[2] + $ints[3] + $ints[4] + $ints[5]; } return $result; } $ints = array(1,2,3,4,5,6); $result = calculate($ints); A faster way would be: $ints = array(1,2,3,4,5,6); eval('$calculate = function () { $result = 0; for ($i=0; $i<10000000; ++$i) { $result += '.$ints[0].' + '.$ints[1].' + '.$ints[2].' + '.$ints[3].' + '.$ints[4].' + '.$ints[5].'; } return $result; };'); $result = $calculate(); The function code it self is in reality more complex and variable in the function-body length, but the princip is the same. The code-architecture, in my specific situation, requires also that the operation encapsulated in a function. (And for security: It is ensured that $int is an 1-dim array filled only with integers) $calculate() works very fine and, of course, much faster than the hardcoded calculate(). Each time $ints is changing i also have, of course, re-define/creater $calculate() via eval. In such situations, for performance reasons, it would makes sense using eval() for re/creating ano-functions, doesn't it? And as long as the function-body has a fixed length each time re/creating the ano-function via eval() it would also not let grow the memory endless.