• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

PHP OOP & require_once Behaviour

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
srinigenie
Asked:
srinigenie
2 Solutions
 
bansidharCommented:
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
 
webvogelCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now