should basic data validation go outside a function or inside?
| From: | Chris W. Parker | Date: | Wed, 10 Nov 2004 19:00:12 +0000 |
| Subject: | should basic data validation go outside a function or inside? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-201710@lists.php.net to get a copy of this message | ||
hi.
call me stupid but i can't decide which option is better (actually don't
call me stupid because it will hurt my feelings and i might cry). and
having said that, maybe neither option is better than the other?
whatever the answer, i just want some outside input on this because for
some reason my brain is getting caught up on it and it's bothering me.
should basic data validation come before a function call or be performed
within the function?
example of validation outside the function:
<?php
if(is_numeric($this->id) && !empty($this->id))
{
$new_number = my_function($this->id);
}
else
{
$new_number = false;
}
?>
example of validation inside the function:
<?php
function my_function($number)
{
if(is_numeric($number) && !empty($number))
{
// perform some calculations
}
else
{
return false;
}
}
$new_number = my_function($this->id)
?>
thanks,
chris.