Introducing PHP 7.4: Performance, Features, Deprecations

Introducing PHP 7.4: Performance, Features, Deprecations

PHP 7.4 has finally appeared! This version that is new released November 28, 2019, is now available on all The Hosting Guy servers. Developers can expect improvements in code readability, maintenance, and ease of use. Let’s look at some of the features that are new performance tweaks along with other factors why you need to migrate to PHP 7.4.

Table of Contents: 

What Does PHP 7.4 Mean for You?

PHP continues to evolve, by releasing their newest PHP 7.4 up-date, high in brand new features. Like we’ve observed in past PHP 7 releases – speed and performance keep improving. One of the most exciting features that are new*********************)preloading. It can help script that is speed-up also presenting the capacity to have quicker and cleaner rule, as a result of the simplification of typical lines of rule.

The good individuals in charge of PHP have actually heard their audience’s opinions and needs and replied them in complete force. They’ve since been code that is continuously changing become more intuitive and better to switch between development languages.

PHP can be used in over 78.9% of most web sites. According to W3techs, the most used web sites PHP that is using are, Pinterest, and Twitter to call several.

(we can see a double speed increase****************)If we specifically look at WordPress sites running PHP, comparing PHP 5 and 7. WordPress powered websites definitely gain the most by using the latest PHP version out there. The Hosting Guy users can super-charge their WordPress sites to heights that are new simply a click of a button.

PHP Usage Statistics

See each one of these figures that are cool? This graph is spitting some truth about web sites earnestly making use of PHP. Are 39,191,714 live websites enough to seize your attention? That’s exactly how many are utilizing PHP right now. Plus PHP 7.4 is testing a lot better than PHP 7.3 with enhanced performance along with other well being improvements.

The graph below programs the overall benchmark test on new and old variations of PHP. A few of the requirements tested were simplicity of use, rate, and gratification amongst others.

PHP Geometric Mean of All Results

Changing Your PHP Variation

Ready to upgrade? Thought so. The Hosting Guy causes it to be as simple as ever with your four steps that are simple. You’ll be fiddling around with your new-and-improved version that is PHP virtually no time.

  1. Log into your The Hosting man account and hit the Home switch.
  2. On your house page, scroll down seriously to the Hosting section and then click in the Manage icon.
  3. In the search field, key in PHP setup and then click about it.
  4. Select PHP 7.4 and simply click Save.
Enabling PHP 7.4 in Hostinger hPanel

Congrats! At this point you get the best & most PHP that is up-to-date version there.

To check your overall version that is PHP all you have to do is visit the Hosting tab and check out the remaining part panel for PHP variation. If it is anything significantly less than 7.4, go right ahead and upgrade.

What’s New in PHP 7.4?

Since 2016, PHP7 was releasing updates that are annual fail. Each they deliver on new features, additions, and the possibility to write cleaner code that makes the language more reliable and user-friendly for those who run it on their websites.( year*******************)

Let’s dig in and simply take a better glance at a number of the modifications that have been made out of the addition of PHP 7.4. For a list that is full out their changelog here.


Let’s talk about rule. When utilizing a framework or libraries, its files need to be linked and loaded on every request. Preloading is when you can load frameworks and libraries into the OPCache. It allows for the server to load the PHP files and store them in memory during startup and have them available for any requests that are future. Mention getting things going fast!

Preloading is run by a specific php.ini directive: opache.preload.This has got the PHP script compiler and executes once the host starts-up. It’s also utilized to preload more files and choose to either include or compile them.

This rocks !, nevertheless, in the event that way to obtain the files that are preloaded ever changed, the server must be restarted. The files that are preloaded remain cached in OPCache memory forever.

However, these files that are preloaded remain designed for any future needs in the event you ever need certainly to utilize them once again.

Spread Operator in Array Expressions

Back whenever PHP 5.6 premiered, PHP started argument that is supporting (spread operator) nevertheless now, with 7.4, we’re able to utilize this function with a selection phrase. Argument unpacking is a syntax for unpacking arrays and Traversables into argument listings. And, to carry out therefore, it just has to be prepended by … (3 dots.) That’s it.

Let’s understand this example:

$animals = ['dog', 'cat'];
$animalkingdom = ['lion', 'elephant', ...$animals, 'giraffe'];
// [‘lion’, ‘elephant’, ‘dog’, ‘cat’, ‘giraffe’];

We are now able to expand a selection from anywhere we wish an additional array, simply by utilizing the Spread Operator syntax.

$num1 = [1, 2, 3];
$num2 = [...$num1]; // [1, 2, 3]
$num3 = [0, ...$num1]; // [0, 1, 2, 3]
$num4 = array( num1 that is...$ ...$num2, 111); // [1, 2, 3, 1, 2, 3, 111]
$num5 = [...$num1, ...$num1]; // [1, 2, 3, 1, 2, 3]

Not just that, you could additionally utilize it in a function. Consider this example:

function getNum() {
  return ['a', 'b'];
$num6 = [...getNum(), 'c']; // ['a', 'b', 'c']
$num7 = [ NumIterator(['a', 'b', 'c'])]; // ['a', 'b', 'c']
function arrGen() {
    for($i = 11; $i < 15; $i++) {
        yield $i;
$num8 = [...arrGen()]; // [11, 12, 13, 14]

In addition, you’re now in a position to unpack arrays and generators which are came back by a function straight into a array that is new

A rule example would appear to be this:

function getAnimals(){
  return ['dog', 'cat', 'elephant'];
$num1 = [...getAnimals(), 'lion', 'tiger', 'giraffe'];

And with PHP 7.4, it could print:

array(6) {
  string(3) "dog"
  string(3) "cat"
  string(8) "elephant"
  string(4) "lion"
  string(5) "tiger"
  string(7) "giraffe"

With this array that is new, spread operators should have means better performance throughout the 7.3 array_merge. The reason being the spread operator is a language structure while array_merge is a function. Additionally because spread operator supports objects implementing traversable and array_merge only supports arrays.

Some considerations to notice, it is possible to just utilize indexed arrays since sequence tips aren’t supported. If utilized, a error that is recoverable be tossed in the display screen, once a string key is available.

Another glorious benefit to 7.4 may be the elimination of the array_merge. Bid farewell to the dreaded index change!

For instance, let’s understand this long array that is winded below:

$array = [‘banana, ‘orange’];
$array[2] = ‘orange’;
$array[1] = ‘apple’; //shifting
// prints 
array(3) {
  string(6) "banana"
  string(5) "apple"
  string(6) "orange"

Another advantage of 7.4 is utilising the generator function. A generator function works exactly like a function that is normal except in the place of coming back a value, a generator function yields as numerous values because it requires to.

Check out of the instance rule below:

function generator() {
  for ($i = 3; $i <= 5; $i++) {
    yield $i;
$num1 = [0, 1, 2, ...generator()];

Weak Recommendations

Now PHP 7.4 has a WeakReference class, that will be not to ever be confused utilizing the class WeakRed or the Weakref extension.

WeakReferences let the programmer remember a guide to an item. This is certainly helpful as it does not avoid the item from being damaged. They have been ideal for applying cache like structures.

WeakReference {
/* Methods */
public __construct ( void )
public static create ( object $referent ) : WeakReference
public get ( void ) : ?object

Contravariant Parameters and Covariant Comes Back

Currently, PHP makes use of parameter that is mostly invariant and return types. Meaning, then the subtype parameter or return type must also be type X.( if a method has a parameter or return type of X*******************)

Now, with PHP 7.4 it proposes to allow covariant (ordered from particular to generic) and contravariant (reversing your order) on parameter and return kinds.

right here is a good example of both:

Covariant return kind example:

interface Factory {
  function make(): object;
class UserFactory implements Factory {
  function make(): User;

Contravariant parameter kind example:

interface Concatable {
  function concat(Iterator $input); 
class Collection implements Concatable {
  // accepts all iterables, not just Iterator
  function concat(iterable $input) {/* . . . */}

Typed Characteristics 2.0

Since PHP 5, kind tips are an feature that is available you to specify the type of variable that is expected to be passed to a function or class. The addition of the object data type gave hope that more would be available in the future in the PHP 7.2 migrations. The long run is currently.

In this new 7.4, PHP has the capacity to offer the type list:

bool, int, float, string, array, object, iterable, self, parent
any class or interface name
?type // where "type" may be any of the above

Note that the parent type may be used in classes and doesn’t need to own a moms and dad in keeping with the parameter and return type.

Also, note that void and callable are not supported. Void was eliminated as it had not been helpful and had semantics that are unclear*********************)Callable, because its behavior had been context-dependent.

Let’s browse even more examples.

right here is a course, written for PHP 7.3:

class User {
    /** @var int $id */
    private $id;
    /** @var string $name */
    private $name;
    public function __construct(int $id, string $name) {
        $this->id = $id;
        $this->name = $name;
    public function getId(): int {
        return $this->id;
    public function setId(int $id): void {
        $this->id = $id;
    public function getName(): string {
        return $this->name;
    public function setName(string $name): void {
        $this->name = $name;

In PHP 7.4, without having to sacrifice any type-safety, a course are now able to be written since simple as:

class User {
    public int $id;
    public string $name;
    public function __construct(int $id, string $name) {
        $this->id = $id;
        $this->name = $name;

Check out samples of most of the types 7.4 now supports:

class Example {
    public int $scalarType;
    protected ClassName $classType;
    private ?ClassName $nullableClassType;
    // Types are also legal on static properties
    public static iterable $staticProp;
    // Types can also be used with the "var" notation
    var bool $flag;
    // Typed properties may have default values (more below)
    public string $str = "foo";
    public ?string $nullableStr = null;
    // The type applies to all properties in one declaration
    public float $x, $y;
    // equivalent to:
    public float $x;
    public float $y;

Arrow Functions 2.0

Anonymous functions in PHP are usually wordy and long, even if they truly are just doing operations that are simple. This is partially due to a amount that is large of boilerplate, and partially as a result of the should manually import utilized factors.

This makes rule that makes use of closures that are simple to learn as well as harder to know.

Let’s appearance at some rule that you’d utilize with PHP 7.3:

function array_values_from_keys($arr, $keys) {
    return array_map(function ($x) use ($arr) { return $arr[$x]; }, $keys);

Now, the following is the more syntax that is concise of 7.4:

function array_values_from_keys($arr, $keys) {
    return array_map(fn($x) => $arr[$x], $keys);

Therefore, arrow functions are in possession of this form:

fn(parameter_list) = expr

Below you can observe a good example of two functions $fn1 (7.3) and $fn2 (7.4) side by part. They’ve the outcome that is same look various:

$y = 1;
$fn1 = fn($x) => $x + $y;
$fn2 = function ($x) use ($y) 
    return $x + $y;

This may also work if the arrow functions are nested:

$z = 1;
$fn = fn($x) => fn($y) => $x * $y + $z;

right here the function that is outer*********************)$z. Then, the inner function also captures $z from the function that is outer. With 7.4, the external range becomes obtainable in the function that is inner. This is certainly one thing 7.3 wasn’t in a position to do.

The arrow function syntax enables many different functions such as for example, variadics, standard values, parameter and return kinds, in addition to by-reference moving and coming back. All while maintaining a clean, readable appearance. Here are most of the valid arrow functions ( that is now available*******************)

fn(array $x) => $x;
fn(): int => $x;
fn($x = 42) => $x;
fn(&$x) => $x;
fn&($x) => $x;
fn($x, ...$rest) => $rest;

One thing to notice is the fact that arrow functions have actually the cheapest precedence. Start to see the example:

fn($x) => $x + $y
// is
fn($x) => ($x + $y)
// not
(fn($x) => $x) + $y


There are numerous deprecations occurring utilizing the merge to 7.4. The list that is following a short overview of the functions targeted for deprecation. You can find a more detailed here:|*************) that is explanation (” class=”synonym”>*************) that is explanation (

  • The real type
  • Magic quotes legacy
  • array_key_exists() with objects
  • 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 directiv

Some essential ones to notice would be the after two-step deprecations.

Changing the Precedence of a Concatenation Operator

Currently the precedence of ‘.’, ‘+’ and operators that are all equal. Any combination of these operators will be solved from simply left-to-right.

Let’s understand this rule in PHP 7.3:

echo "sum: " . $a + $b; 
// would be evaluated left-to-right
echo ("sum: " . $a) + $b;
// could also look like this

With PHP 7.4, ‘+’ and ‘-’ would simply take precedence over ‘.’ so that the improvements and subtractions would be performed before always the string. This would look like the ( that is following*******************)

echo "sum: " . $a + $b; 
// would be executed as if the code were as follows.
echo "sum :" . ($a + $b);

This two-step proposition aims become less error-prone and more instinctive. PHP 7.4 presently is within the stage that is first a deprecation notice of un-parenthesized expressions of ‘+’, ‘-’ and ‘.’ While waiting for the vote/change that is final in PHP 8.

Left-Associative Ternary Operator

Unlike almost every other languages, the operator that is ternary PHP is left-associative as opposed to right-associative. Not merely being unusual, it’s also confusing for coders whom switch between various languages. PHP 7.4 proposes to get rid of the left-associativity and needs the utilization of parentheses rather.

Let’s take a good look at the rule below:

return $a == 1 ? 'one'
     : $a == 2 ? 'two'
     : $a == 3 ? 'three'
     : $a == 4 ? 'four'
               : 'other';

In almost every other languages it will be interpreted as:

return $a == 1 ? 'one'
     : ($a == 2 ? 'two'
     : ($a == 3 ? 'three'
     : ($a == 4 ? 'four'
               : 'other')))

whilst in PHP, it really is alternatively interpreted as:

return ((($a == 1 ? 'one'
     : $a == 2) ? 'two'
     : $a == 3) ? 'three'
     : $a == 4) ? 'four'
               : 'other';

This can cause mistakes as it’s generally speaking perhaps not that which was meant.

Through a different two-step proposition, PHP 7.4 has implemented the explicit utilization of parentheses as a deprecation caution and certainly will ideally carry a compile runtime error out in future variations.


Just with time for the holiday season, PHP 7.4 brings features that are new well being improvements for several PHP developers.

WordPress web sites will surely take advantage of these improvements and their users can get quicker execution times much less memory use whenever PHP that is using 7.4 with earlier incarnations.

With the addition of first-class home kind declarations and kind hinting, arrow merging functions, and a ridiculously better rate, the 7.4 will certainly enhance both the rate and quality of one’s workflow.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x