Is your plugin code safe for PHP 5.4 and 5.5 and 5.6?
by
, 30 Mar 2014 at 04:55 AM (84158 Views)
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.
(Remember: PHP 5.3 added the abbreviated ternary for "?:")
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
- stricter about array handling
- function array dereferencing: foo()[0]
- Class member access on instantiation has been added, e.g. (new Foo)->bar().- Class::{expr}() syntax is now supported.
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!
- added Class name resolution via ::class
- added opcache extension
- generators and finally declaration added
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
- added Constant expressions
- added variadic "..." ("splat") operator
- Exponentiation via **
- default_charset() is now the default
- added hash_equals()
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