Page 1 of 1
Include all function files at top or require_once as needed
Posted: Sat Sep 12, 2009 2:29 pm
by joeshmoe666
I have been segregating similar functions into individual files and including all the files at the top. Another programmer I know puts them into individual files also but only uses require_once in a file that calls the functions. I prefer my way because then I don't have to remember the require_once everytime I use a function in my file, but I was wondering about performance. Does PHP load the full function code into the code page or heap or just the function header .. either way how many functions would you have to be using before there was a performance impact ? Also is it better to segregate similar functions into different files or put most or all of them into one big file .. I know why that's not good for development reasons but how about performance reasons?
Thanks
Re: Include all function files at top or require_once as needed
Posted: Sat Sep 12, 2009 3:46 pm
by jackpf
I doubt it'll make any noticeable difference. PHP is very fast.
I just have one huge functions file...but they're all separated into classes...so it's nice and neat.
Re: Include all function files at top or require_once as needed
Posted: Sat Sep 12, 2009 5:43 pm
by josh
I use auto loading ( objects ). Later if I wanted I could merge all my class definitions. A profiler will tell you quickly that executing 10k LOC in 1 file is much faster then queueing 10k separate files for reading. A good IDE will be able to 'jump' to the function definition regardless so I would not even consider typing out the extra code for documentation purpose
Re: Include all function files at top or require_once as needed
Posted: Mon Sep 14, 2009 5:38 pm
by joeshmoe666
Thanks for the tips guys .. I was referring to procedural code rather than oop .. but what you said makes sense either way..