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