On Tue, Oct 4, 2016 at 8:33 AM, Pascal KISSIAN <php-mailing-l...@lool.fr> wrote:
> >-----Message d'origine----- > >De : Lauri Kenttä [mailto:lauri.ken...@gmail.com] > >Envoyé : mardi 4 octobre 2016 16:21 > >À : Pascal KISSIAN <php-mailing-l...@lool.fr> > >Cc : internals@lists.php.net > >Objet : Re: [PHP-DEV] Feature Request: inline pseudo-instruction > > > >On 2016-10-04 14:33, Pascal KISSIAN wrote: > >> I have an application where a small file is included at multiple > >> places. > >> > >> The include is done about an average of 100.000 times . > > > >I'm just wondering if you have ever heard of functions? You really should > write a function, include it only once, and then simply call the function > instead of repeatedly >including the file. Calling a function is a lot > faster than including a file. > > > >-- > >Lauri Kenttä > > Function is not appropriate when the "inlined code" has to share 20-30 > local variables ... > Having a function with 30 args, or having to build and access an array is > not very efficient nor natural... > Local variables include 6 nested "for loop" indices and local > variables/arrays needed for the computing. > As many have said this may be a sign of a need to refactor. however, to say that building an array and accessing it is not natural, consider that you can use compact / extract. function doLoops($vars) { extract($vars); // many for loops return compact(implode(' ', array_keys($vars))); } // elsewhere set up a bunch of variables extract(doLoops(compact('list of variable names goes here'))); Problem solved, now you are not including in a loop, but calling an already compiled function, without adding TONS of lines of code to build such an array. Its a short solution, to a problem that should probably lead to a redesign of the functionality anyway. > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >