Jump to content

Handling multiple includes


phppup

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.