请考虑这个例子。 (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;
}
}
这两种方法的优点是什么?它们在哪里适用?
虽然数据库连接可能有多个结果集,我只会保存最近的结果,并且以后调用的方法也会使用这个。所以我还不清楚:S – shxfee 2010-02-18 14:06:29