Q: include vs inculde_once?

Fred <[email protected]>
Newsgroups gmane.comp.web.oscommerce.suggestions
Message-ID <35a5d901dcfce5d501eecda2c915d045@osCommerce-Forums>
This message was sent from: Suggestions and Proposals
http://forums.oscommerce.com/viewtopic.php?p=171569#171569
----------------------------------------------------------------

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: 

[code]// 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'];
        }[/code]

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

/Fred
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.