<?php class Point { public readonly string $name; public function __construct( public readonly int $x, public readonly int $y, ) {} public function setName(string $name): static { $this->name ??= $name; return $this; } } $p = new Point(3, 4); $p->setName('Larry'); var_dump($p); $rClass = new \ReflectionClass(Point::class); $new = $rClass->newInstanceWithoutConstructor(); $setter = (fn (string $k, mixed $v) => $this->$k = $v)->bindTo($new, $new); $setter('x', 3); $setter('y', 4); $setter('name', 'Larry'); var_dump($new);
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`