Solved

php includes vs requires vs include_once

Posted on 2013-06-18
5
401 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 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

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
The viewer will learn how to dynamically set the form action using jQuery.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

687 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