?
Solved

php includes vs requires vs include_once

Posted on 2013-06-18
5
Medium Priority
?
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
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 1600 total points
ID: 39258441
Then use require_once('database.php') in both file minion1.php and minion2.php
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 400 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This article discusses how to implement server side field validation and display customized error messages to the client.
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)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

741 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