Speed and security is the target in everything we do, this time we decided to switch all of our customers to PHP 7.4 for various reasons mentioned below:
1. Preloading for Improved Performance
A boost in performance is always welcome. With PHP 7.4, you can configure opcache to compile your code files first, and then save them in shared memory.
Doing this enables you to make these files freely available, rather than having to compile them every time there is a request:
This is a lot like caching for end users, and offers similar benefits. Improved performance means that you can work more efficiently, have a better UX, and meet those pressing deadlines.
2. Arrow Functions for Cleaner One-Line Functions
Anything that enables you to write shorter code is a helpful improvement to PHP’s UX. The good news is that 7.4 will include arrow functions, which help you shorten your anonymous functions.
They allow the usage of short closures when creating one-line functions:
Arrow functions work by defining the expression in the parent scope. In that way, they can certainly help when it comes to making your code less verbose.
3. Typed Properties for Cleaner Code
As with arrow functions, typed properties also help to clean up your code, which is another positive development. With typed properties, you can now easily declare type hints to class variables and properties.
In addition, you can now declare types on static properties. In other words, class variables can be type hinted:
The great part about this is that it cuts down on unnecessary boiler plate code. It does so by making sure you don’t have to use getter and setter methods to enforce type contracts.
4. WeakReferences for Retaining a Reference to an Object
WeakReferences enable you to retain a reference to an object, without preventing the object from being destroyed. This new function works similar to a cache structure:
WeakReferences are helpful for some types of object-oriented design that need to index a reference. You can use them by installing the PECL Weakref extension to improve UX for certain projects.
5. Deprecations in Preparation for PHP 8.0
Deprecations are old features that are no longer needed, or won’t function after the implementation of an update. Some of the deprecations to look out for in PHP 7.4 include:
- Short open tags are to be removed.
- The left-associative ternary operator will likely be removed, which means you’ll have to use explicit parentheses instead.
- Curly brace syntax are no longer used, only square brackets.
These changes are in preparation for the next major program update to PHP 8.0. As the software evolves, you can expect more deprecations, as well as new functions and commands to replace them.
Since the 1990s, PHP has been one of the strongest languages for server-side programming. It continues to evolve to this day, with a new update dropping in November 2019.
This update comes with a number of important changes and new features for web developers. As we’ve seen, these include:
- Preloading for improved performance
- Arrow functions for cleaner one-line functions
- Typed properties for cleaner code
- WeakReferences for retaining a reference to an object
- Deprecations in preparation for PHP 8.0
Do you have a question or any issue with your website since this update? Please don't hesitate to write us at [email protected].
Thursday, January 2, 2020