Re: should basic data validation go outside a function or inside?
| From: | Brad Pauly | Date: | Wed, 10 Nov 2004 21:54:03 +0000 |
| Subject: | Re: should basic data validation go outside a function or inside? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201725@lists.php.net to get a copy of this message | ||
On Wed, 10 Nov 2004 11:00:12 -0800, Chris W. Parker
<cparker@swatgear.com> wrote:
> 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?
I would do the validation inside the function. This avoids repeating
the validation everywhere the function is called. It also makes the
function more self-contained. It expects a certain input and
complains, or returns false, if it doesn't get it.
Brad