PHP 7.4 New Features

  1. Typed properties
  2. Arrow functions
  3. Null coalescing assignment operator
  4. Custom object serialization
  5. Unpacking inside arrays

1. Typed properties

Typed class properties: string, int, float, etc. are now available.

2. Arrow functions

Arrow functions follow the format fn (argument_list) => expr, variables within scope are available inside the arrow function.

3. Null coalescing assignment operator ??=

A short hand version of if !isset, then assign.

4. Custom object serialization

The magic methods __serialize and __unserialize can be used for custom object serialization.

5. Unpacking inside arrays

The ... spread operator can be used within arrays.

Detailed information on PHP 7.4

PHP 7.3 New Features

  1. Trailing commas in function calls

1. Trailing commas in function calls

A trailing , does not result in an error when calling a function.

Detailed information on PHP 7.3

PHP 7.2 New Features

  1. New object type
  2. Abstract method overriding

1. New object type

Type object can be used as a parameter and return type.

2. Abstract method overriding

Abstract methods can be overridden, within extending abstract classes.

Detailed information on PHP 7.2

PHP 7.1 New Features

  1. Nullable types
  2. Void functions
  3. Negative string offsets

1. Nullable types

Abstract methods can be overridden, within extending abstract classes.

2. Void functions

Functions can declare a return type void. Returning NULL in that case will result in an error.

3. Negative string offsets

Negative string offsets are now possible, counting from the end of the string: -1, -2, -3 etc.

Detailed information on PHP 7.1

PHP 7.0 New Features

  1. Scalar type declarations/Return type declarations
  2. Null coalescing operator
  3. Spaceship operator
  4. Cryptographically secure pseudo-random bytes/integers

1. Scalar type declarations/Return type declarations

Function parameters and function return types can be declared as string, float, int, etc.

2. Null coalescing operator ??

The null coalescing operator ?? can used as a short hand for exists and is not NULL. The ?? operator can also be chained.

3. Spaceship operator <==>

The spaceship operator <==> compares two values and returns 0, -1, or 1. It returns 0 if both compared values are equal, -1 if the left value < the right value, 1 if the left value > the right value. It can be used to compare int, string, etc.

4. Cryptographically secure pseudo-random bytes/integers

Cryptographically secure bytes/integers is now available for use with salts, passwords, etc.

Detailed information on PHP 7.0

Further Reading

In this article we looked at the key new features of PHP 7, a detailed list of PHP features can be found here.