Option 1: query the data first and then pass the data to the constructor
Option 2: use the constructor to query the data and then fill the properties
Option 1 Example
$val1 = 1;
$query = mysql_query("SELECT val2, val3, val4 FROM table WHERE val1 = '".$val1."'");
$row = mysql_fetch_assoc($query);
$o = new Class($row['val1'], $row['val2'], $row['val3'], $row['val4']);
Option 2 Example
$val1 = 1;
$o = new Class($val1);
// in Class constructor
public function __construct($val1) {
$query = mysql_query("SELECT val2, val3, val4 FROM table WHERE val1 = '".$val1."'");
$row = mysql_fetch_assoc($query);
$this->val1 = $row['val1'];
$this->val2 = $row['val2'];
// etc ...
}
NOTES
I am perfectly aware that mysql_query
is deprecated. Please resist the overwhelming urge to tell me that and contact my PM instead.
I am asking if Option 2 is bad practice or if there are any foreseen predicaments that are overwhelmingly known in the object oriented space. It seems to be the cleaner option to me.