Please consider this example. (PHP)
class Database{
private $result;
private $conn;
function query($sql){
$result = $this->conn->query($sql);
// Set the Database::$result ?? Or return the value and avoid setting property?
return $result;
// $this->result = $result;
}
}
what are the advantages of both these methods? Where are they applicable?
Your recent comments indicate that you will only be keeping a single result set around at a time. This being the case, I would suggest saving it to the object itself (as a data member of the object).
Also, since you are only keeping around a single result set, you might rename your class to something more descriptive. “Database” doesn’t quite summarize it. It is a “ResultSet”. If it’s a particular type of result set consider naming it so it reflects the type of data you are fetching.