json_encode()
class MyClass implements JsonSerializable {
public function jsonSerialize() {
return json_encode([1, 2, "44"]);
}
}
$c = new MyClass();
echo json_encode($c);
In this example after calling json_encode($c)
function, JsonSerializable
will be called automatically because the class MyClass
implements JsonSerializable