- var_dump: documentation ( source)
- json_decode: documentation ( source)
- json_encode: documentation ( source)
<?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);