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]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to