例: 身長と体重から BMI を自動計算 PHP 8.4 で追加 class Person { public function __construct( public float $height, public float $weight, ) { } public float $bmi { get => $this->weight / pow($this->height / 100, 2); } } $person = new Person(170.5, 60.3); echo sprintf("%.2f", $person->bmi) . PHP_EOL; # 出力: 20.74 5 / 16