Solved

php includes vs requires vs include_once

Posted on 2013-06-18
5
385 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
ID: 39258417
0
 
LVL 9

Author Comment

by:Evan Cutler
ID: 39258426
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
ID: 39258441
Then use require_once('database.php') in both file minion1.php and minion2.php
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 39259274
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
ID: 39264225
Thanks guys.  That helps.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article discusses four methods for overlaying images in a container on a web page
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

733 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