mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 11:36:23 +00:00
745 B
745 B
id | title |
---|---|
19579c31-1dcc-4d11-b2f8-5f9180fa66d3 | PHP constructor property promotion |
Description
Introduced in PHP 8.0, constructor property promotions1 add new syntatctic sugar to create value & data transfer objects.
Syntax
class Money
{
public Currency $currency;
public int $amount;
public function __construct(
Currency $currency,
int $amount,
) {
$this->currency = $currency;
$this->amount = $amount;
}
}
can be replaced with
class Money
{
public function __construct(
public Currency $currency,
public int $amount,
) {}
}