A value object was a property declaration, a constructor parameter and an assignment for every field — three lines each, all of them saying the same thing.
// 7.4
final class Money
{
private int $cents;
private string $currency;
public function __construct(int $cents, string $currency)
{
$this->cents = $cents;
$this->currency = $currency;
}
}
// 8.0
final class Money
{
public function __construct(
private int $cents,
private string $currency,
) {}
}
The trailing comma after the last parameter is allowed and worth using, because adding a field is then a one-line diff. Promotion only works in a constructor and only for properties with no default beyond the parameter default, so a class with a computed property still declares that one normally — and mixing the two forms in one class reads badly enough to be worth avoiding. It does not work with callable, which is the one type that cannot be a property.