Latest News: (loading..)
cornishpirate

PHP 7

65 posts in this topic

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!

Share this post


Link to post
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. 

Edited by xinn2005

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I am using v2.3.4.

 

I guess I could replace the "boxes" with div based code but it would not change the hierarchy of the classes that caused the error. 

Share this post


Link to post
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

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

@dr_lucas Exactly the topic I've been searching for! I did some similar work but it didn't go through. Will take a closer look. Thanks a bunch!

Share this post


Link to post
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

Share this post


Link to post
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;

    }  

Share this post


Link to post
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. 

Share this post


Link to post
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

Edited by Dan Cole

Share this post


Link to post
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.

Edited by BrockleyJohn

Share this post


Link to post
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

Share this post


Link to post
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.

Edited by BrockleyJohn

Share this post


Link to post
Share on other sites

Hello @@BrockleyJohn,

I can not change the encryption, the tpv server is the one that uses. Redsys technical service (payment gateway) says to enable mcrypt on the server, it has always been enabled!!!

Regards

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now