- var_dump: documentation ( source)
- json_decode: documentation ( source)
- json_encode: documentation ( source)
<?php
class Period implements JsonSerializable
{
private $startDate;
private $endDate;
public function __construct()
{
$this->startDate = new DateTimeImmutable('2015-04-03');
$this->endDate = new DateTimeImmutable('2015-05-03');
}
public function jsonSerialize()
{
return [
'startDate' => $this->startDate,
'endDate' => $this->endDate,
];
}
}
$period = new Period();
var_dump(json_decode(json_encode($period)));