<?php class A implements JsonSerializable{ public $baz = 10; function jsonSerialize(){ return ['bar' => 20]; } } class B implements JsonSerializable{ function jsonSerialize(){ return ['foo' => (new A)->jsonSerialize()]; } } echo json_encode(new B, JSON_PRETTY_PRINT);
You have javascript disabled. You will not be able to edit any code.