3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class Foo { private $x; public function setX($x) : Foo { $this->x = $x; return $this; } public function getX() { return $this->x; } } function test($class) { if (class_exists($class)) { return new $class(); } return null; } $x = test('Foo')->setX('test'); var_dump($x->getX());

preferences:
27.2 ms | 402 KiB | 5 Q