- json_encode: documentation ( source)
<?php
class Foo {
public $barPublic = 1;
protected $barProtected = 2;
private $barPrivate = 3;
public function toJson() {
return json_encode($this);
}
}
$foo = new Foo();
echo $foo->toJson();