PHP Class Tostring

class Role
{
    private $id;
    private $code;
    private $name;
    private $description;

    public function __construct($id, $code, $name, $description)
    {
        $this->id = $id;
        $this->code = $code;
        $this->name = $name;
        $this->description = $description;

    }

    public function __setId($id)
    {
        $this->id = $id;
    }

    public function __getId()
    {
        return $this->id;
    }

    public function __setCode($code)
    {
        $this->code = $code;
    }

    public function __getCode()
    {
        return $this->code;
    }

    public function __setName($name)
    {
        $this->name = $name;
    }

    public function __getName()
    {
        return $this->name;
    }

    public function __setDescription($description)
    {
        $this->description = $description;
    }

    public function __getDescription()
    {
        return $this->description;
    }

}

 $role = new Role(1, "ROLE_ADMIN", "ADMIN ROLE", "Only For Admins");
 echo json_encode($role); // it displays {} empty json
///Bicodev.com
Bicodev