Skip to content
Advertisement

PHP – Split code into multiple files or keep it in as few files as possible? [closed]

Right now I have a script that has reached 400 KB in 4 files (about 3500 lines per file).

Should I split it into more files?

Does having more files have a impact on performance because of multiple require_once calls?

Advertisement

Answer

I have a large, 13000 line script that I combined from three others, but it’s entirely view and user-management related, dealing with output and receiving input. The functions are in another, 8000 line file, and I make sure there’s zero bleedover between the two. No HTML in the functions file, no SQL in the main file. Would this be different if I could use objects? Of course. Can’t.

So the moral of the story is: It all depends on what makes you comfortable for the script in question. I have one other that is 5 small files because it makes more sense that way; this one makes sense as two large ones.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement