Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Q: include vs inculde_once?


Guest

Recommended Posts

Posted

I have a case where I need to create two instances of the same class, i.e the payment class. The thing is that when I create the second instance I get this error "Fatal error: Cannot redeclare class payment in checkout_paypalipn.php on line 15". This is due to how the payment class is written, it's the include statement in the constructor that is causing this. Why use "include" instead of "include_once"? Is there a reason to this? Is it safe to change the code to:

 

// class constructor

   function payment($module = '') {

     global $payment, $language, $PHP_SELF;



       ...



       for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {

         //changed from "include" to "include_once"

         //include(DIR_WS_LANGUAGES . $language . '/modules/payment/' . $include_modules[$i]['file']);

         //include(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']);

         include_once(DIR_WS_LANGUAGES . $language . '/modules/payment/' . $include_modules[$i]['file']);

         include_once(DIR_WS_MODULES . 'payment/' . $include_modules[$i]['file']);



         $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];

       }

 

If it's safe I think this should be implemented all over the shop.

 

/Fred

Posted

I think it is due to php3 compatibility.. that doesn't support include_once I think.

"Politics is the art of preventing people from taking part in affairs which properly concern them"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...