PHP 8 · Types and functions

Declare properties in the constructor

Define and assign properties from constructor parameters.

class User
{
    public function __construct(
        public readonly string $name,
        public readonly string $email,
    ) {}
}

Official PHP 8 documentation

More types and functions commands

All types and functions commands · PHP 8 cheatsheet

Was this page helpful?