I'm creating a User object and the constructor pulls user data from the database when the object is created. Its set up so that it can pull data either by knowing the UserID or the user's email.
function __construct ($db_obj, $userID=0) {
$this->_db_obj = $db_obj;
if (is_numeric ($userID))
$where_str = "userID = $userID";
else
$where_str = "user_email LIKE :user_email";
$get_user_obj = $db_obj->prepare ("SLECT * FROM Users WHERE $where_str");
$get_user_obj->bindParam (":user_email", $userID);
$get_user_obj->execute();
// Do some stuff
}
Is it allowable to use a bindParam method on a parameter that may not be there? Is it better for me to just split this into two different functions (which would seem to go against the DRY principle)?