3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for git.master, git.master_jit
object(Point)#1 (3) { ["name"]=> string(5) "Larry" ["x"]=> int(3) ["y"]=> int(4) } object(Point)#3 (3) { ["name"]=> string(5) "Larry" ["x"]=> int(3) ["y"]=> int(4) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
47.52 ms | 405 KiB | 5 Q