- json_encode: documentation ( source)
<?php
class A {
protected $a = 'a';
}
class B implements \JsonSerialize {
protected $a;
function __construct(A $a)
{
$this->a = $a;
}
public function jsonSerialize()
{
return [
'a' => $this->a
];
}
}
$b = new B(new A());
echo json_encode($b);