3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A implements \JsonSerializable { public $prop; public function jsonSerialize() { $obj = new stdClass; if ($this->prop) { $obj->prop = $this->prop; } return $obj; } } class B implements \JsonSerializable { public $a; public function jsonSerialize() { $obj = new stdClass; if ($this->a) { $obj->a = $this->a; } return $obj; } } $a = new A; $b = new B; $b->a = $a; var_dump(json_encode($b));

preferences:
26.45 ms | 405 KiB | 5 Q