Class Tree · Level 6 of 7

Written once

A Point whose properties are declared right in the constructor and marked readonly.

<?phpclass Point {    public function __construct(        public readonly int $x,        public readonly int $y = 0,    ) {}    public function withX(int $x): static {        return new static($x, $this->y);    }}$p = new Point(1, 2);echo "$p->x,$p->y\n";try {    $p->x = 5;} catch (Error $e) {    echo $e->getMessage(), "\n";}$q = $p->withX(5);echo "$q->x,$q->y / $p->x,$p->y\n";

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…
  3. 3…