Saturday, March 30, 2024

PHP 7.3 vs 7.4

In PHP 7.3, you can use type declarations in functions:

abstract class Controller {
    protected $registry;
    protected $customer,
    public function __construct(Registry $registry) {
        $this->registry = $registry;
    }
    public function getCustomer(): Customer {
        return $customer;
    }

But type declaration for the properties will cause errors like "Parse error: syntax error, unexpected 'Registry' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)":

    protected Registry $registry;
    protected Customer $customer;

Typed properties was introduced in PHP 7.4.

No comments:

Post a Comment