- json_encode: documentation ( source)
<?php
class Foo
{
private $bar;
private $baz;
public function __construct($bar, $baz)
{
$this->bar = $bar;
$this->baz = $baz;
}
}
$foo = new Foo('hello','word');
$string = json_encode($foo);
echo $string;