PHP 7.4 is the latest minor PHP update, and the last before the next major version, PHP 8, is released. As with any update, new features have been introduced, and there are also some changes to be aware of. In this article, I’ll talk about what’s new in PHP 7.4, what’s going away, and when you should consider upgrading the PHP version your website uses.
What’s New in PHP 7.4
Some welcome changes and new features have been added as PHP continues to adapt and improve.
Most of the changes are “non-breaking,” meaning you can upgrade and your site will continue to work normally. (Assuming you’re upgrading from an earlier version of PHP 7.)
But some changes might have an effect on your existing code. You can check this list of backward-incompatible changes to see if your codebase is affected.
Here are the most interesting PHP 7.4 changes to be aware of.
- Arrow functions – also called “short closures,” arrow functions allow you to write shorter, single-line functions.
- Typed properties – allows for type-hinting in class variables.
- Preloading – improves performance by loading PHP files (say, from your favorite framework) into server memory on startup. That way, they’re always available for requests.
- Type variance – improvements have been made to allow for covariant return types and contravariant arguments.
- Weak References – previously available as an extension, weak references let you refer to objects without preventing them from being destroyed.
- Null coalescing assignment operator – lets you create shorter null coalescing operations.
- Spread operators in arrays – allows for the use of a spread operator in arrays and numerical keys.
- Numeric literal separator – allows you to use underscores as a format to separate numeric values.
- Custom object serialization – introduces two new magic methods, __serialize, and __unserialize.
That’s not absolutely everything, of course. Here’s a list of all of the changes.
What’s Going Away
The introduction of new versions always means some old methods and functions are retired and deprecated. PHP 7.4 is no exception.
The following functions are deprecated in PHP 7.4. They will likely be removed in PHP 8 (the next PHP major version release).
- The real type.
- Magic quotes legacy.
- array_key_exists() with objects.
- FILTER_SANITIZE_MAGIC_QUOTES filter.
- Reflection export() methods.
- mb_strrpos() with encoding as 3rd argument.
- implode() parameter order mix.
- Unbinding $this from non-static closures.
- hebrevc() function.
- convert_cyr_string() function.
- money_format() function.
- ezmlm_hash() function.
- restore_include_path() function.
- allow_url_include ini directive.
When Is the Right Time to Switch to a Newer Version of PHP?
At the beginning of this article, I mentioned that PHP 7.4 is the last update before PHP 8. I know some of you out there are still using PHP 5, so that might come as a surprise. You may be wondering when you should consider making a move to a new version. (Not to mention, what the heck happened to PHP 6?)
Like any software, PHP limits how long they support a particular version. Unsupported versions typically aren’t updated unless a serious security flaw is uncovered. Beyond supporting versions, they also set a time frame for “end of life.”
After the end of life date, security flaws may not even be patched. So, it goes without saying that it’s best not to use any software past its end of life.
Most web hosting companies will gradually phase out end of life server software like PHP. When that happens, your account can be involuntarily upgraded to a more recent version.
And therein lies the answer to the “When should I switch versions?” question. The answer is, before the end of life!
“Can” VS “Should”
When I say hosts will phase out outdated software “gradually,” I do mean gradually. GreenGeeks, for instance, like many hosts, will still let you use some PHP 5 versions that reached their end of life almost ten years ago.
But just because you can continue to use those old versions doesn’t mean you should.
If you stay as up to date as you can, upgrading is much less painful. PHP 5.6, for example, reached its end of life less than two years ago. But when you update a PHP 5.6 site to PHP 7.x, you’ll find that there are some significant changes that have to be made.
Especially for sites that use databases (and which site doesn’t these days?).
Often we find ourselves with older sites that we maintain for archival purposes. Maybe there’s still useful information on them, but we don’t necessarily add anything new. It’s easy to avoid (or simply forget about) upgrading the infrastructure of those kinds of sites.
But if you ignore those sites, you could find yourself facing an involuntary upgrade. If that upgrade is likely to break the site, you’ll be forced to make changes quickly. That’s not the best way to approach any website update.
Often, sites that fall into disrepair are simply abandoned, and in many cases, that’s a loss for all of us.
So take some time now to do an inventory of your websites and which technologies they use. If necessary, schedule some time to update them. It’s not fun or glamorous work, but it will save you potential trouble down the road.
If You’re a GreenGeeks Customer
GreenGeeks will make PHP 7.4 the “native” PHP version on all servers on October 1st, 2020. The previous native PHP version was 7.2.
We have tested PHP 7.4 thoroughly throughout our platform. PHP 7.4 includes important improvements over the existing native version, PHP 7.2, and boasts increased performance and efficiency.
If you want to switch to PHP 7.4 at any time before our update, here’s how to do it.
If you have any questions or concerns about PHP changes, contact us! We’re always available to answer your questions.