Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP 7


cornishpirate

Recommended Posts

Dan, well it started as RC2a !

 

It's very heavily modified, both in terms of keeping it updated, secure, improving efficiency, making it responsive and extending facilities.

 

However, it didn't take too much to make it run under PHP 7. I just made a point of ensuring all notices, warnings and errors from the log were dealt with.

 

Alan

 

PS Having a lifetime in software developement helped!

Link to comment
Share on other sites

  • Replies 93
  • Created
  • Last Reply
  • 8 months later...

I just upgraded the PHP version to 7.0 for my website. While most warnings were fixed by replacing the old class constructors with __construct(), there are some pretty serious issues with the child class calling parent class constructors in the original code. For example, includes/classes/message_stack.php extends tableBox and has some code that created the "Call to undefined method" error:

 

class tableBox {

   // class constructor

    function __construct($contents, $direct_output = false) { ... }

}

 

class messageStack extends tableBox {

    function __construct() { ... }

 

   function output($class) {

       ..............    

     // the line below throws Call to undefined method error

     return $this->tableBox($output);

 }

 

Replacing the line above with parent::__construct() didn't work. I would appreciate it if you could share your thoughts on this. 

Link to comment
Share on other sites

I just upgraded the PHP version to 7.0 for my website. While most warnings were fixed by replacing the old class constructors with __construct(), there are some pretty serious issues with the child class calling parent class constructors in the original code. For example, includes/classes/message_stack.php extends tableBox and has some code that created the "Call to undefined method" error:

 

class tableBox {

   // class constructor

    function __construct($contents, $direct_output = false) { ... }

}

 

class messageStack extends tableBox {

    function __construct() { ... }

 

   function output($class) {

       ..............    

     // the line below throws Call to undefined method error

     return $this->tableBox($output);

 }

 

Replacing the line above with parent::__construct() didn't work. I would appreciate it if you could share your thoughts on this.

 

to be fair, you should use these boxes any more.

shouldn t be too hard to find examples of how to rewrite these in modern div based code

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

@@xinn2005  Cindy you might want to have a look and see what was done to fix it, if anything, on the EDGE version.  I think it is PHP 7 ready.

 

Dan

Link to comment
Share on other sites

Link to comment
Share on other sites

@@Dan Cole Thanks for the info Dan! I was actually looking for the PHP7 compatible version. Another way to deal with it is to bypass calls to messageStack within create_account. Will see how these approaches work out. Appreciate your help!

Link to comment
Share on other sites

Hi all

This is correct?

Original code

  class cm_navbar {
    var $code;
    var $group;
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function cm_navbar() {
      $this->code = get_class($this);
      $this->group = basename(dirname(__FILE__));

      $this->title = MODULE_CONTENT_NAVBAR_TITLE;
      $this->description = MODULE_CONTENT_NAVBAR_DESCRIPTION;

      if ( defined('MODULE_CONTENT_NAVBAR_STATUS') ) {
        $this->sort_order = MODULE_CONTENT_NAVBAR_SORT_ORDER;
        $this->enabled = (MODULE_CONTENT_NAVBAR_STATUS == 'True');
      }
    }

Changed code for php7.1

  class cm_navbar {
    var $code;
    var $group;
    var $title;
    var $description;
    var $sort_order;
    var $enabled = false;

    function __construct() {
      $this->code = get_class($this);
      $this->group = basename(dirname(__FILE__));

      $this->title = MODULE_CONTENT_NAVBAR_TITLE;
      $this->description = MODULE_CONTENT_NAVBAR_DESCRIPTION;

      if ( defined('MODULE_CONTENT_NAVBAR_STATUS') ) {
        $this->sort_order = MODULE_CONTENT_NAVBAR_SORT_ORDER;
        $this->enabled = (MODULE_CONTENT_NAVBAR_STATUS == 'True');
      }
    }

The cange is line 21

Regards

No external links here, thank you

Link to comment
Share on other sites

Thanks for everybody's input. Here are the changes I made and tested successfully. In addition to the messageStack sub class I had to make similar modifications to the child classes defined in boxes.php such as infoBox, contentBox, etc. To be honest I found these classes around the "boxes" a bit confusing and over-complicated but at least they keep my website running at the moment. 

 

class tableBox {
   // class constructor
    

    function __construct() {...} // empty constructor

    function __tableBox($contents, $direct_output = false) { ... } // moved all code from the original constructor to this function

}
 
class messageStack extends tableBox {
    function __construct() {

        parent::__construct();

        // other actions

    }

   

    function output($class) {

        $contents = parent::tableBlock($output); 

        return $contents;

    }  

Link to comment
Share on other sites

 

Dan - I had a quick look at the link above and found that the class constructor format, __construct(), required by PHP7 was not present in almost all classes. I modified my code because my hosting company upgraded the server environment to php7. I would assume that the oscommerce community should be aware of this fix. Again - I truly appreciate your timely help. 

Link to comment
Share on other sites

Dan - I had a quick look at the link above and found that the class constructor format, __construct(), required by PHP7 was not present in almost all classes. I modified my code because my hosting company upgraded the server environment to php7. I would assume that the oscommerce community should be aware of this fix. Again - I truly appreciate your timely help. 

 

@@xinn2005

 

Hi Cindy, the changes required for php7 compatibility are a bit lost on me (actually more then a bit) but I'll reference @@BrockleyJohn who has been actively involved in that project so he is aware of this thread and your changes.  Thanks for your input and posts.

 

Dan

Link to comment
Share on other sites

Dan - I had a quick look at the link above and found that the class constructor format, __construct(), required by PHP7 was not present in almost all classes. I modified my code because my hosting company upgraded the server environment to php7. I would assume that the oscommerce community should be aware of this fix. Again - I truly appreciate your timely help.

 

@inn2005

Hi Cindy, you need to be looking in the php7 branch not the master branch to pick up these changes. Following the link previously given without changing branches will (currently) take you here: https://github.com/BrockleyJohn/Responsive-osCommerce/tree/php7_compatibility_01/

 

It's not actually a requirement of php7 to have the constructor defined, so you don't necessarily have a method __construct unless there is a need for it.  You cannot have a method with the same name as the class unless you have a __construct method, though.

 

That said, I don't remember any classes not having a constructor.

 

If you have found any classes in this branch that are not php7 compliant please send me a link - it means I've made a mistake rebuilding a new branch to get rid of conflicts with master.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

Hi, wath is the correct code fro work whit php7

error:

Deprecated: Function mcrypt_encrypt() is deprecated in /httpdocs/includes/modules/payment/apiRedsys/apiRedsysFinal.php on line 70
	function encrypt_3DES($message, $key){
		// Se establece un IV por defecto
		$bytes = array(0,0,0,0,0,0,0,0); //byte [] IV = {0, 0, 0, 0, 0, 0, 0, 0}
		$iv = implode(array_map("chr", $bytes)); //PHP 4 >= 4.0.2

		// Se cifra
		$ciphertext = mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv); //PHP 4 >= 4.0.2
		return $ciphertext;
	}

Regards

No external links here, thank you

Link to comment
Share on other sites

Hi, wath is the correct code fro work whit php7

error:

Deprecated: Function mcrypt_encrypt() is deprecated in /httpdocs/includes/modules/payment/apiRedsys/apiRedsysFinal.php on line 70
	function encrypt_3DES($message, $key){
		// Se establece un IV por defecto
		$bytes = array(0,0,0,0,0,0,0,0); //byte [] IV = {0, 0, 0, 0, 0, 0, 0, 0}
		$iv = implode(array_map("chr", $bytes)); //PHP 4 >= 4.0.2

		// Se cifra
		$ciphertext = mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv); //PHP 4 >= 4.0.2
		return $ciphertext;
	}

Regards

 

Oh dear!

 

You can replace the encryption with another that is supported eg. openssl_encrypt but whether that will work depends on whether it produces exactly the same encryption result (I've a feeling it doesn't) and what happens with the returned result.

 

If you are just using it within the module to compare against something that has been passed to the payment provider and returned, then it might work.

 

However, if it's used on the other side of the api you need to use the same encryption that they are using.

 

Thirdly, if it's encrypting something that is stored (like a password) then all stored values will be junk if you change the encryption and should be removed or ignored.

 

I think I came across Magento hitting this issue in their core code last year but I don't recall seeing what they did about it.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

Redsys technical service (payment gateway) says to enable mcrypt on the server, it has always been enabled!!!

Tell them that mcrypt encryption is deprecated on php7 and soon it will be removed altogether. If they don't do anything about it very soon they won't have any php-based customers.

 

In the meantime, start talking to some other providers. Check if their api works on php7. If there's not a payment module available for osc, one can be written but they're quite a lot of work so I don't suppose anyone will do it for free!

 

If you need this working in the short term while you sort out a proper solution, it's possible to suppress deprecated notices so that the code still runs through properly.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...