Zen Cart Logo
Forums / Contribution-Writing Guidelines / deprecated constructors

deprecated constructors

Views: 28,604

Results 1 to 5 of 5
30 Jun 2019, 9:14 PM
#1
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

deprecated constructors

with 1.5.6b and PHP 7.1.30, I get a few notices saying PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; ec_analytics has a deprecated constructorIf I change the method to```php
__ec_analytics()

30 Jun 2019, 9:29 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: deprecated constructors

The constructor for a class would become just the generic:
__construct()

member.

But, need to also look through the code to see if there are/were specific calls to the member function ec_analytics other than declaring a new variable of that type.

If so, then it may be desirable to add a __construct() function above the existing function of the class' name and then have that function call the old constructor...

Sorry, digress a little.

Adding two underscores in front of the existing name won't resolve the usage issue.

Further note this format is becoming required in php 7.x but has been available since at least early php 5.x.

30 Jun 2019, 9:40 PM
#3
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: deprecated constructors

OK, thanks for the info. I searched and don't see where any of the affected modules' methods are called so I changed them to __construct() and the notices have disappeared. This was in ec analytics, keep cart, search log and back in stock notifications observer classes. Since it's just a notice it's probably not worth updating the mods at this point.

30 Jun 2019, 9:50 PM
#4
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: deprecated constructors

lankeeyankee:

Since it's just a notice it's probably not worth updating the mods at this point.
That is where i disagree with you. This IS the time to update, because now it is only a warning. in a next php version, that warning will become a fatal error, because the constructor is not allowed to be the same as the class name any more.
So you could see this as a friendly reminder of php to tell you it is time to change that piece of code. Don't wait until it is broken. :hug:

30 Jun 2019, 10:21 PM
#5
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: deprecated constructors

OK, I will test it a bit on my dev 1.5.6b for a bit to see if anything else needs changing then will upload the updated packages. There are a few other notices that I don't really know how to correct, it's been so long since I've done anything beyond some basic changes that I have forgotten much. I will post the specific issues in the related threads to see if others can help solve the issues.