Solved

php includes vs requires vs include_once

Posted on 2013-06-18
5
361 Views
Last Modified: 2013-06-20
Is there a way to drop an include after it's been called?
I have a folder architecture like this:

Master.php
database.php
Minions (folder)
- minion1.php
- minion2.php

minion1.php and minion2.php must use database.php.
but if I call from Master.php, I get a confliction.

The problem is that include_once doesn't pick up the "already loaded" trigger because it's calling them from different locations.

Help?
Thanks
0
Comment
Question by:Evan Cutler
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
Comment Utility
0
 
LVL 9

Author Comment

by:Evan Cutler
Comment Utility
Thanks. .. I know how to call them.... my problem is that master.php is calling the other two.  I am getting an error that a library used in minion1.php is also called in minion2.php.  I am getting the (cannot reinitialize variable)
0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 400 total points
Comment Utility
Then use require_once('database.php') in both file minion1.php and minion2.php
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
Comment Utility
Is there a way to drop an include after it's been called?
No.  You can unset() the variables that were created by include() but you cannot undo the execution of the code that was brought into scope by include()
...include_once doesn't pick up the "already loaded" trigger because it's calling them from different locations.
Eh?  How do you test for the success of include_once()?  Please show us the exact code that can be used to reproduce the problem.  It may be path-related?  We will be able to help once we see the file structure and the include_once() statements.
0
 
LVL 9

Author Closing Comment

by:Evan Cutler
Comment Utility
Thanks guys.  That helps.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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 dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 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