Solved

PHP OOP & require_once Behaviour

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending an image to a php webservice via cURL from command line 7 34
Dynamic varibles 5 33
Insert won't work due to space in column name 5 21
php simple error message 4 23
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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 …

777 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