Signatur
public function __construct(public readonly string $name) {}
Beschreibung
Sichtbarkeits-Modifier (public, protected, private, readonly) im Konstruktor-Parameter deklarieren die Property automatisch.
Rückgabewert
Typ
void
Beispiele
Vorher / Nachher
<?php
// Alt
class Point {
public float $x;
public float $y;
public function __construct(float $x, float $y) {
$this->x = $x;
$this->y = $y;
}
}
// Neu
class Point {
public function __construct(
public readonly float $x,
public readonly float $y,
) {}
}