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.

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, v1.5.3, v1.5.4 and 1.6.0 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 even if short_open_tag is set to off in php.ini
- for error_reporting, E_ALL now includes E_STRICT level errors
- 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:
- some SERIOUS speed improvement was added
- mysql_xxxx() functions no longer valid. Use mysqli_xxxx() instead. (or PDO if your code is based on that)
- can't use the /e modifier with preg_replace anymore. Use preg_replace_callback() instead.
- a set of password-hashing functions was added: you should no longer be writing your own hashing algorithms!

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


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 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