​ The fastest PHP in history is available now. PHP ships with plenty of new features and performance improvements. Out of these new features, these are the ones we are more excited about:

JIT Compilation

​ PHP 8 now ships with a Just-In-Time compiler that promises to deliver an incredible boost in performance. We are excited to see what performance gains await Drupal in this regard. ​

Attributes

​ For those of us Psalm users, no longer do we need to create annotations using PHPDoc comments. Instead, we can use the new structure available in PHP for this purpose:

Bye-bye:

/**
 * @deprecated No longer used. To be removed in next version.
 */
function count() {
  ...
}

Hello:

#[Deprecated(
    reason: 'No longer used. To be removed in next version.'
)]
function count() {
  ...
}

Match expression:

We can simplify simple switch cases using the brand new Match expression, like so: ​

Bye-bye:

switch ($platform) {
  case 'joomla';
    $result = 'good';
    break;

  case 'symfony':
    $result = 'great';
    break;

  case 'drupal':
    $result = 'better';
    break;
}
echo $result;

Hello:

echo match($platform) {
  'joomla' => 'good',
  'symfony' => 'great',
  'drupal' => 'better'
};

Nullsafe operator:

​ Instead of multiple check conditions, we can now use one single expression. If one element in the chain evaluates to a falsy value, the whole expression evaluates to NULL. ​

Bye-bye:

if ($user) {
  $address = $user->getAddress();
  if ($address) {
    $city = $address->getCity();
    return $city;
  }
}

Hello:

return $user?->getAddress()?->getCity();

Constructor property promotion

​ Last, but definitely not least, injecting services will now be faster thanks to the Constructor Property Promotion feature in PHP 8. ​

Bye-bye:

class SomeDrupalService {

  protected $token;

  protected $fileSystem;

  public function __construct(Token $token, FileSystemInterface $file_system) {
    $this->token = $token;
    $this->fileSystem = $file_system;
  }

}

Hello:

class SomeDrupalService {

  public function __construct(
    protected Token $token,
    protected FileSystemInterface $file_system) {
    ...
  }

}