phppup Posted August 9, 2022 Share Posted August 9, 2022 Is there an advisable/best practice for using multiple includes? I've found several instances where the same scripting was being used repeatedly. I also realized that using includes could shrink the overall length of my scripts (making them easier to manage). //The file MainFile1 contains 4 includes (some are sequentially necessary rather than one larger include) MainFile1 - include external01 - include external02 - include external03 - include external04 OR this MainFile1 - include external01 //The file external01 contains an include external01 - include external02 //The file external02 contains TWO includes external02 - include external03 - include external04 Is there a benefit in processing speed or efficiency to be gained? Quote Link to comment https://forums.phpfreaks.com/topic/315159-handling-multiple-includes/ Share on other sites More sharing options...
benanamen Posted August 9, 2022 Share Posted August 9, 2022 1 hour ago, phppup said: I've found several instances where the same scripting was being used repeatedly. I also realized that using includes could shrink the overall length of my scripts (making them easier to manage). You pretty much answered your question. Without seeing what you are actually including it is hard to say if what YOU are doing is good or not. Your repeated code may be a good candidate for a function or a class, or an include may be the right solution. Just cant say without seeing what you have. If you are able, put your project on a public GitHub repo so we can review it as a whole. You will get much better and specific answers to what you are doing. Quote Link to comment https://forums.phpfreaks.com/topic/315159-handling-multiple-includes/#findComment-1599198 Share on other sites More sharing options...
ginerjm Posted August 9, 2022 Share Posted August 9, 2022 Adding a block of code to a script using the include or require construct is a normal method of building a program. It allows you to create something to accomplish a task whether it is a boilerplate of html or css or JS or plain old PHP. You write it, perfect it and use it where it is then needed. Kind of like the use of function as mentioned earlier in this topic. It's not rocket science and doesn't really have to involve any mystery as it seems to be doing in your post. It is not a way of shortening your script since when it is used it builds your script to the exact same length. It is simply a way of making something and using it wherever it is needed. Just like a function, which quite often is added to a script via the include statement as well. Does that answer your concerns? Quote Link to comment https://forums.phpfreaks.com/topic/315159-handling-multiple-includes/#findComment-1599199 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.