Re: Adding validate_var_array()/validate_input_array() to which version?
| From: | Rowan Collins | Date: | Thu, 04 Aug 2016 21:04:16 +0000 |
| Subject: | Re: Adding validate_var_array()/validate_input_array() to which version? | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-94836@lists.php.net to get a copy of this message | ||
Hi Yasuo,
On 04/08/2016 20:29, Yasuo Ohgaki wrote:
One of my objective is following best practices. Prefer exception over error is one of them. Although, I strongly suggest to use exception for validation errors, I will have choices.Best practice is to use exceptions to indicate an error *inside* the function, i.e. something going wrong with the function itself. If I run (as a simplified example) validate_var('abc', FILTER_NUMERIC) that's not something going wrong inside validate_var(), so validate_var() shouldn't be throwing an exception, IMO. Now, the *reason* I'm calling validate_var may be that the function I'm writing will go wrong if the validation doesn't pass, but that's up to *me* to throw an exception: if ( validate_var($foo, FILTER_NUMERIC) ) {
throw new InvalidArgumentException;} That said, in another message you explained that this isn't intended for "validation" in the sense of "form validation", but in a more restricted sense of "dangerous data"; I think the name misled me, and may mislead others, if that is the sole purpose of the function. I'm still not entirely convinced, though, that a boolean-returning function wouldn't be enough to fill both purposes. Regards, -- Rowan Collins [IMSoP]