A file with multiple functions OR multiple files with a function?

Asked

Viewed 241 times

1

In the scope of my design use include("funcoes.php"), inside that file has all the functions I use in different parts of the project, I don’t use all the functions all the time.

So a doubt!

Pro system would be more advantageous, with respect to performance, use only this include and leave all functions there, or make several files, where each has its given function, and as the need of the use of the function use the include("nome.funcao.php"), or the gain would not be so advantageous, so it would be easier to keep a single file and centralize everything in the same scope!

My question is this. In this file I have about 30 functions, simple functions even the most complex, only that I don’t use the 30 all the time, and the file include("funcoes.php") is included at the top of all pages, so assuming I use 5 functions, the other 25 were loaded "atoa".

  • related: https://answall.com/questions/203510/um-arquivo-com-v%C3%A1rias-fun%C3%A7%C3%B5es-ou-v%C3%A1rios-arquivos-com-uma-fun%C3%A7%C3%A3o (I don’t mean it’s a solution)

  • 1

    related: https://answall.com/questions/74647/unir-arquivos-php-em-um-s%C3%B3-increases-a-performance

  • @Danielomine gave a read! Already gave a help!

  • I would create a file for each function...becomes lighter and clear the project...

  • I believe that if it is not an absurdly large file it will not make a difference, that you will only notice testing, it is very relative, however an idea can be categorizing these functions, for example, a file for functions related to dates and times, other for strings and etc... so you get a middle.

2 answers

1


Creating a file for each function is only relevant if they are very extensive functions, if they are relatively short functions the difference will be minimal and perhaps imperceptible.
So if you prefer to do everything in one file do it in several do it in several.

1


In this amount of functions, that is irrelevant.

Hardly you will find a file by function in old systems that used this structure that is now considered unproductive, unless you are doing something very simple or an embedded system.

We must privilege modern writing, taking advantage of object orientation that has become robust in recent years and use the autoload of objects in Namespaces, which will carry only what is called.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.