?
Solved

PHP OOP & require_once Behaviour

Posted on 2009-04-01
3
Medium Priority
?
394 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 100 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 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 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