3v4l.org

run code in 300+ PHP versions simultaneously
<?php class integer { private $value; public function __construct(int ...$value) { switch (count($value)) { case 0: break; case 1: $this->value = $value[0]; break; default: throw new Exception('Multiple values given.'); } } public function __invoke(int ...$value) : int { switch (count($value)) { case 0: break; case 1: $this->value = $value[0]; break; default: throw new Exception('Multiple values given.'); } return $this->value; } public function __toString() : int { return $this->value; } } $testi = new integer(); $testi(2); $copy = $testi; var_dump($copy); echo $testi;

preferences:
49.33 ms | 402 KiB | 5 Q