Loading certain PHP functions

I have one function file for my entire site, and for one page, 90% of the file is not even called. Therefore, I want to load only those functions that are called on the page, and I am new to php.

+1
function php
Jul 28 2018-11-11T00:
source share
5 answers

A group is combined into several objects with common features, making them static functions and placing each object in a separate file. Then use the PHP5 autoload functions to load the corresponding objects only when they are in use.

+2
Jul 28 2018-11-11T00:
source share

You can split this file into many small files and include only what you need to use.

However, if it is not a large file, it will not reduce your performance at all.

+1
Jul 28 2018-11-11T00:
source share

You can split the file of your functions into several files, but remember that if you need more files, downloading can be even slower because you need more I / O commands to load different files.

Moreover, you separate files by functionality. If you feel that all these functions belong to each other, keep them together in this file. This will not slow down your script.

If you like, you can put functions in (static) classes and use the autoloader to load the file, but I am not a supporter of this solution. I believe that static classes are just a pretext for getting functions (and vars) from the global realm, and creating classes just for automatic loading is an abuse of autoload functionality. Of course, if you create a more object-oriented script, using classes also makes sense, and loading them can be convenient.

+1
Jul 28 '11 at 8:43
source share

Actually, it’s not a problem to have a function available for use, but you only use it in your application. More importantly, you have everything when you need it, without real worries about when to download.

If your system is growing, then you can look for an autoloader. PHP supports autoload of classes , but not for functions. However, you can group your functions into classes (some of them will delete me to create such a statement), then use autoload.

+1
Jul 28 '11 at 8:43
source share

If your file size is small, it will not reduce your performance at all. If you want to achieve your goal, perform group functions and put them in separate files and include only the necessary files ...

0
Jul 28 '11 at 8:52
source share



All Articles