Initialize objects right into the constructor parameters in PHP 8.1

1 · Amit Merchant · Sept. 10, 2021, 10:41 p.m.
With the introduction of PHP 8, the language now allows us to declare the class properties right into the constructor parameters. This is called constructor property promotion. Initializing objects in constructor properties Restrictions In closing So, instead of doing so… <?php class Book { private string $name; private string $author; public function __construct( string $name = 'The Alchemist', string $author = 'Paulo Coelho' ) { $this->name = $name;...