Is it necessary to validate function parameters or not?
<p>When i write down a function is a good practice to validate all the parameters of the function like this:</p>

<pre><code>&lt;?php
/**
 * foo - Test function
 *
 * @param int $paramA
 * @param str $paramB
 * @param array $paramC
 *
 * @return something
 */
function foo($paramA, $paramB, $paramC) {
    // verify all parameters
    if(!is_int($paramA)) {
        return 0; // or error msg
    }
    if(!is_string($paramB)) {
        return 1; // or error msg
    }
    if(!is_array($paramC)) {
        return 2; // or error msg
    }

    // some code in function scope that uses parameters 
    // and saves the results in $result
    return $result;
}
</code></pre>

<p>or should i rely on the user that will use the function and assume that he knows what he is doing and forget about parameter validation?</p>

<p>Personally i prefer to validate all the parameter of the function and return error codes for consistency of the code and make my life easier afterwords.</p>

<p>Thank you in advance.</p>
