3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo implements JsonSerializable { private $een; private $twee; public function __construct(string $een, int $twee = null) { $this->een = $een; $this->twee = $twee; } public function getEen(): string { return $this->een; } public function getTwee(): int { return $this->twee; } public function jsonSerialize(): array { return [$this->een, $this->twee]; } } $first = new Foo('thestring'); $storage = json_encode($first); var_dump($storage); $second = new Foo(...json_decode($storage, true)); var_dump($second);

preferences:
18.81 ms | 402 KiB | 5 Q