View RSS Feed

Behind The Code, with DrByte

Is your plugin ready for PHP 7.0, 7.1, 7.2?

Rating: 5 votes, 3.80 average.
This the 3rd in a series about readying your plugins for PHP 5.3, and for PHP 5.4, 5.5 and 5.6.

NOTE: This post assumes some pretty solid PHP knowledge, because all the changes listed will require adapting your code to find a new way to do whatever it was doing before.

NOTE: This is not the complete official list of changes. I've edited this list down to the basics, catering mostly to the topics that might affect people writing plugins for Zen Cart. For much more detailed lists of changes, see the official PHP documentation on migrating between PHP versions.



In PHP 7.0 the following functionality/features changed:
a) class constructors must be called __construct and not just be the same function name as the class anymore.
b) indirection - use of $$foo['bar']['baz'] needs to be rewritten as ${$foo['bar']['baz']} else it will be seen as ($$foo)['bar']['baz']. Also, $foo->$bar['baz'] has to be rewritten as $foo->{$bar['baz']} if that's what was intended.
c) switch() statements cannot have multiple "default:" blocks

In PHP 7.1 there were numerous changes, but few likely to impact regular Zen Cart use

For PHP 7.2 the following changes are to be deprecated:
a) calls to each() are deprecated; use foreach() instead. See examples here: Refactor each() to foreach() for compatibility with PHP 7.2
b) create_function() is deprecated. Use anonymous functions instead.
c) The __autoload() mechanism is deprecated in favor of spl_autoload_register() instead.


On github I've posted a gist containing some regex patterns which can be used to identify incompatible old PHP code

Submit "Is your plugin ready for PHP 7.0, 7.1, 7.2?" to Digg Submit "Is your plugin ready for PHP 7.0, 7.1, 7.2?" to del.icio.us Submit "Is your plugin ready for PHP 7.0, 7.1, 7.2?" to StumbleUpon Submit "Is your plugin ready for PHP 7.0, 7.1, 7.2?" to Google

Categories
Uncategorized
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR