How should I handle the input validation of a method?
Of these two, which one is the more correct way? or there is a better way
This method is called by the constructor and $prodID can be user input or come from the db.
private function fill_data1($prodID)
{
//Way 1
filter_var($prodID, FILTER_VALIDATE_INT, array('options'=>array('min_range'=>1, 'max_range'=>1000000)));
if (is_null($prodID)) {
return FALSE;
} elseif ($prodID === FALSE) {
return FALSE;
}
$prod = getArtData($prodID);
$this->set_id($prod['artID']);
$this->set_name($prod['artName']);
$this->set_price($prod['precio']);
}
private function fill_data(2$prodID)
{
//Way 2
filter_var($prodID, FILTER_VALIDATE_INT, array('options'=>array('min_range'=>1, 'max_range'=>1000000)));
if (is_null($prodID) || $prodID === FALSE)
{
die('invalid input for prodID (' . $prodID . '). It has to be an integer > 0');
}
$prod = getArtData($prodID);
$this->set_id($prod['artID']);
$this->set_name($prod['artName']);
$this->set_price($prod['precio']);
}