Solved

PHP OOP & require_once Behaviour

Posted on 2009-04-01
3
378 Views
Last Modified: 2013-11-10
Hi all,

  I have a 3rd party PHP class (present in directory ../lib/POC/include) that I need to use. In my calling PHP code, I have included the root path (.../lib) using  php function 'set_include_path'. My problem in using the PHP class is

 3rd party PHP class has require_once statements on top of the file containing the class. So if I use this class, will the require_once statements also come over?? Else how do I handle such a situation and use these 3rd party classes?

Thanks,
Srini

// Filename class.Chat.inc inside directory lib/POC/include
 

require_once(POC_BASE.'/config.inc.php');
 

require_once(POC_INCLUDE_PATH.'/adodb/adodb.inc.php');

require_once(POC_INCLUDE_PATH.'/class.Language.inc');

require_once(POC_INCLUDE_PATH.'/class.Chatter.inc');
 

class POC_Chat {

  

...

Open in new window

0
Comment
Question by:srinigenie
3 Comments
 
LVL 11

Accepted Solution

by:
bansidhar earned 25 total points
ID: 24047098
if you include a php file, all the code inside the file gets processed. So the require_once() statements inside the file also come into effect.

I think you will require those other files mentioned in the class for its working, so avoiding those is not a good option.

If you are already including those files in your code, you can use the require_once() so it will never be included more than once even if you call require_once again for the same file. eg:

require_once('my_other_file.php); // here the my_other_file.php is included to your code
require_once('my_other_file.php); // here the my_other_file.php is  NOT included to your code again. So even if you add the same statement to any other file you have included the my_other_file.php will not be re-added there.

Hope this clears your problem
0
 
LVL 3

Assisted Solution

by:webvogel
webvogel earned 25 total points
ID: 24552454
Search for where POC_INCLUDE_PATH and POC_BASE is defined and change it to the right path.
Try this or absolute path:
define('POC_BASE', '.') ;
define('POC_INCLUDE_PATH', './POC/include');
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

15 Experts available now in Live!

Get 1:1 Help Now