Fundamentals5 / 5
Up next

Classes

<?php
class Point {
    public function __construct(
        private int $x,
        private int $y,
    ) {}

    public function manhattan(): int {
        return abs($this->x) + abs($this->y);
    }
}

echo (new Point(3, -4))->manhattan();
What you're solving

constructor property promotion