Solved

Unique includes

Posted on 2002-04-23
5
217 Views
Last Modified: 2013-11-18
HI,

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.

Thanks,
0
Comment
Question by:c96jg
5 Comments
 
LVL 5

Expert Comment

by:dkjariwala
Comment Utility
You can use include_once or require_once depending on what you need to do.

JD
0
 
LVL 4

Expert Comment

by:lokeshv
Comment Utility
can do with

if(!function_exists(any_function_name)){


    include("yourfile.php");
}


Lk
0
 
LVL 7

Expert Comment

by:axis_img
Comment Utility
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.

http://www.php.net/manual/en/function.include-once.php

http://www.php.net/manual/en/function.get-included-files.php

Regards,
Barry
0
 

Author Comment

by:c96jg
Comment Utility
HI,

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?

Jim
0
 
LVL 4

Accepted Solution

by:
Gibble earned 200 total points
Comment Utility
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)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now