Solved

php includes vs requires vs include_once

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

20 Experts available now in Live!

Get 1:1 Help Now