Unique includes

Posted on 2002-04-23
Last Modified: 2013-11-18

I think if there is a positive answer to this, then it'll be a complicated answer.

What I want to do is call some PHP script that is determined by values in the db, this will be performed in a loop n number of time. n will be determined by the number of records in the db.

The problems is, if the same peace of script is include more than once, there is potential clash of defined functions within the scripts.

I don't want to have to make sure all the scripts (in time potently 100's, if not 1000's) have unique function names.

Because of this, include and require are of no use to me, does anyone have a alternative idea, of how I could achieve this?

What I really want to be able to do is run or de_include an include file.

Question by:c96jg

Expert Comment

ID: 6964022
You can use include_once or require_once depending on what you need to do.


Expert Comment

ID: 6964521
can do with




Expert Comment

ID: 6964564
In my opinion, the method dkjariwala mentioned is the most efficient way. I always use include_once() for my scripts, as it just keeps you from making stupid mistakes by accidentally including the same file (functions) twice.

There is also the ability to see what files are included by using the get_included_files() function, but include_once() is the best method.


Author Comment

ID: 6965078

Thanks for the responses but include_once or require_once doesn’t solve the problem, as it is possible there will be code that gets executed on the inclusion. I.e. code not in a function. This code will need to be executed every time the inclusion happens. I can get a work around but would like to avoid it if I can.

Plus as implied in the question, there may in time be 2 or more functions with the same name in differant include doing differant things. Which is why I'm looking for a run type thing as oposed to an include.

Any other ideas?


Accepted Solution

Gibble earned 200 total points
ID: 6968960
Manage the names, if they are for one application there should NEVER be two functions with the same name.

Adopt a standard naming scheme with some sort of namespace as part of the function name eg. app1_addrow()  or app2_addrow().

Otherwise you will never know what function you have, or what you are really using. (PS, putting functions in objects is another way to 'namespace' your function names)

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Undefined variable problem 5 22
Link failure 16 33
Correct syntax for subdirectories 9 18
Wordpress Query 5 25
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question