Solved

PHP OOP & require_once Behaviour

Posted on 2009-04-01
3
389 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
[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
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

Industry Leaders: 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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 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