View RSS Feed

Behind The Code, with DrByte

Is your plugin code safe for PHP 5.4 and 5.5 and 5.6?

Rating: 45 votes, 4.91 average.
This is a follow-up post to my previous post about readying your plugins for PHP 5.3, this time addressing PHP 5.4, 5.5 and 5.6. Also check out the next one: for PHP 7.0, 7.1, 7.2, 7.3

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.

NOTE: Zen Cart v1.5.2 thru 1.5.6 have incorporated fixes for all of the following.


In PHP 5.4 the following functionality/features changed:
- Short Array Syntax was added ... ie: instead of array('foo'=>'bar') you can use ['foo'=>'bar'] ... any code using this Short Array Syntax requires minimum PHP 5.4
- magic-quotes is no longer used. You should remove calls to get_magic_quotes_gpc(), get_magic_quotes_runtime(), set_magic_quotes_runtime()
- safe_mode can no longer be used and register_globals is no longer valid in php.ini
- if you had break or continue commands that passed an argument using a variable, you must remove that variable, and rewrite the loop a new way
- timezone can no longer be set by using the TZ environment variable. Instead you must set date.timezone in php.ini or call date_default_timezone_set(), else a warning will be issued
- <?= now works again for equivalent to 'echo' even if short_open_tag is set to off in php.ini
- html_special_chars and html_entities now default to utf8
- is a LOT more strict about array handling

In PHP 5.5 the following features/functionality changed:
- mysql_xxxx() functions no longer valid. Use mysqli_xxxx() instead. (or PDO if your code is based on that)
- some SERIOUS speed improvement was added
- password-hashing functions were added: you should no longer be writing your own hashing algorithms!

For PHP 5.6 the following changes are part of 5.6:
- $HTTP_RAW_POST_DATA is retired
- numerous improvements to OpenSSL support were added


Note: the long $HTTP_xxxxx_VAR variables should no longer be used anywhere!

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

PLEASE NOTE THE OFFICIAL PHP VERSION SUPPORT TIMELINE: http://php.net/supported-versions.php

Submit "Is your plugin code safe for PHP 5.4 and 5.5 and 5.6?" to Digg Submit "Is your plugin code safe for PHP 5.4 and 5.5 and 5.6?" to del.icio.us Submit "Is your plugin code safe for PHP 5.4 and 5.5 and 5.6?" to StumbleUpon Submit "Is your plugin code safe for PHP 5.4 and 5.5 and 5.6?" to Google

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