« tell me what you need, and I would tell you how to do without it » is a nonsense answer for me…
I just told you about one among several cases where I found the need for such a feature. I can also tell you, by example, of a specific grammar driven php writen parser where about 100 functions have their 2 first lines and 3 ending lines exactly the same… Another use would be to have an « inlined code » containing the begining of a loop structure, and another one the ending of that loop structure…. (that is no more possible with include in new php versions but it was possible in older ones, not considering performance issues) And don’t tell me that it is bad coding, or rewrote whole php source code without macros before. As an example : ZEND_HASH_FOREACH_VAL and ZEND_HASH_FOREACH_END are very usefull for php itself. Why do not allow php to have such kind of functionnalities? Before thinking about macros, the 1st little step, not so difficult to implement, would be, according to me, to have an inline statement that does the same as include, but at compile time instead of at runtime… And my only question is : “Am I the only people needing this kind of feature?” If I am the only one, just do as if I never posted to this forum, but if many people think it could be usefull, perhaps it would make sense to reconsider the question. Best regards, Pascal KISSIAN De : Michał Brzuchalski [mailto:mic...@brzuchalski.com] Envoyé : mardi 4 octobre 2016 17:52 À : Bob Weinand Cc : Pascal KISSIAN; PHP internals list Objet : Re: [PHP-DEV] Feature Request: inline pseudo-instruction 2016-10-04 17:39 GMT+02:00 Bob Weinand <bobw...@hotmail.com>: > Am 4.10.2016 um 16:33 schrieb Pascal KISSIAN <php-mailing-l...@lool.fr>: > >> -----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. 6-level nested loop and 20-30 local variables in scope has enought complexity to refactor. This stuff definitelly needs refactor. I wouldn't allow any developer to commit such code, it woudn't pass code review. There was time I also have such code but it wasn't maintainable, once written was never beeing understood by any other developer. I think you should read about CleanCode -> https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 Hey, why do you think are your includes so slow? Apart from the include itself (which in itself is fairly slow due to filesystem access; or in case with opcache, at the very least copying the op_array etc.), it does exactly this: building an array and importing it into the included files scope. Also, 20-30 local variables? That sounds a bit like your code has way too many responsibilities in one same place. Perhaps you should restructure your code instead, but the way you describe it, no. If your code is so "hot", that also even function calls would be quite significant then you should probably really inline your code there as a perf optimization. Anyway, code with that many variables almost always can meaningfully refactored. It is not the languages task to optimize insane code ... Bob -- regards / pozdrawiam, -- Michał Brzuchalski brzuchalski.com <https://brzuchalski.com/>