3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/Los_Angeles'); class Fruit { public $type = 'Apple', $lastEaten = null; public function __construct() { $this->lastEaten = new DateTime(); } public function jsonSerialize() { return array( 'type' => $this->type, 'lastEaten' => $this->lastEaten->format(DateTime::ISO8601) ); } } echo $s = json_encode(new Fruit()); var_dump(json_decode($s));

preferences:
36.87 ms | 402 KiB | 5 Q