Blog

PHP 7.4.0 is now released!

php7-4-0-webepower

PHP Development team announces the immediate availability of PHP7.4.0 in the market. This release has the fourth updation of the PHP7 series.

PHP7.4.0 comes with numerous improvement and the new features such as:

PHP 7.4.0 comes with a remarkable amount of new features in the 7.4.0 list. We will discuss with the list of features, and then discuss changes and deprecations.

Let’s understand though with a few highlights, include in PHP 7.4:

  • Arrow functions for one-liner function.
  • Preloading for improve performance.
  • Typed properties in classes.
  • FFI for extension development in PHP.
  • Spread operator in arrays.
  • The null coalescing assignment operator as shorthand.

1. Arrow functions

Before arrow functions, function like map, filter, reduce that receive function as a parameter, had to be described as following:

 $multiplier = 2;

$doubledCity = array_map(function ($city) use ($multiplier) {
return $city * $multiplier;
}, $cities);

Now with the new syntax the code can be written as:

{
public string $age;

public ?Foo $foo;
}

They are only available in classes and require access to access specifiers public, protected and private.

3. Typed Properties:

Preloading is going to be controlled by just a single new php.ini directive opcache.preload. Using this directive we can specify a single PHP file that will perform the preloading task. The preloaded files remain in the cached in opcache memory. During the preloading process, PHP resolves class dependencies and links with the parent, interfaces, and traits.

4. Foreign function interface:

PHP Foreign Function Interface or FFI is a PHP extension that allows you to include with some externals libraries to your PHP code. That means it’s possible to use C, GO, RUST etc shared the library with your code without writing a PHP Extension in c. FFI will become really interesting when the CPU is bounded: DOM management, big array, complex calculation, etc.

5. Spread Operator:

It’s now possible to use Spread operator in arrays

{
public string $age;

public ?Foo $foo;
}

6. Null coalescing assignment operator:

It’s is shorthand of null coalescing operator in the earlier version. Instead of previous version

$details['date'] = $details['date'] ?? new DateTime();

You can now do this

$details['date'] ?? = new DateTime();

Deprecation:

Apart from the new features, there is also deprecation of the previous functions or library.

1. Nested ternary operators without explicit parentheses

<?php
1 ? 2 : 3 ? 4 : 5;   // deprecated
(1 ? 2 : 3) ? 4 : 5; // ok
1 ? 2 : (3 ? 4 : 5); // ok
?>

2. Allow_url_include INI option

The allow_url_include in the directive is deprecated. Enabling this in your code can generate a deprecation notice at startup.

3. Magic quotes functions

The get_magic_quotes_gpc() and get_magic_quotes_runtime() function are deprecated. They always return false.

4. Filter

FILTER_SANITIZE_MAGIC_QUOTES is deprecated, use FILTER_SANITIZE_ADD_SLASHES instead.

5. (real) cast and is_real() function

The (real) cast is deprecated, use (float) instead.

The is_real() function is also deprecated, use is_float() instead.

Conclusion

PHP 7.4.0 is the new version where new features can provide you the better development and you can improvise your code stability by using the new feature of PHP 7.4.0. If you have any doubts regarding this article you can feel free to contact us. We want to hear from you.