Serializes the object to a value that can be serialized natively by
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
by Valeri Tandilashvili
4 years ago
PHP
OOP
PHP Object Oriented Programming (OOP)
2
Pro tip: use ```triple backticks around text``` to write in code fences