Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu 18.04 - Install PHP 7.4



sudo apt install -y software-properties-common apt-transport-https \
  && sudo add-apt-repository ppa:ondrej/php -y \
  && sudo apt update \
  && sudo apt install php7.4-cli -y

Key New Features

Typed Properties!


class User {
    private int $id;
    private string $name;
    private FooClass $foo;

Allow exceptions from __toString()

Throwing exceptions from __toString() is now permitted. Previously this resulted in a fatal error. Existing recoverable fatal errors in string conversions have been converted to Error exceptions. This is important to me because of my use of the AbstractView package.

Unpacking Inside Arrays

$parts = ['apple', 'pear'];
$fruits = ['banana', 'orange', ...$parts, 'watermelon']; // ['banana', 'orange', 'apple', 'pear', 'watermelon'];

Limited return type covariance and argument type contravariance

Even though the return types are different for the same method declaration, this will work because B extends A, so is a super type.

class A {}
class B extends A {}

class Producer {
    public function method(): A {}
class ChildProducer extends Producer {
    public function method(): B {}


Last updated: 15th September 2020
First published: 17th March 2020