Checking user privileges before executing functions
<p>This is more of a concept question. I would like to get an advice from very experienced members on how to better arrange my code. Often when handling user's requests we need to check their privileges in order to determine their rights to execute some function or method. The question is whether it is better to verify access rights prior to executing a function like so:</p>

<pre><code>//handling some POST data from AJAX
//lets assume we have some function check_some_rights() which takes user id as argument and returns 1 if user has some right or 0 if he/she doesnt
    if (check_some_rights($user)){ //the privileges are verified
        some_function_that_does_some_stuff()
    } else {//nope, this user got no right to do this
        echo "Like hell you do!";//denying access to this user
    }
</code></pre>

<p>Or is it better to check access rights as soon as execution of function is initiated like so:</p>

<pre><code>//alternative solution with embedded privilege check
function some_function_that_does_some_stuff($user){
    if (check_some_rights($user)){//the privileges are verified
        //go on with the procedure
        // ...
    } else {
        echo "Like hell you do!";//denying access to this user
    }
}
</code></pre>

<p>I personally believe that the second approach would be better, because we wouldn't have to worry remembering to check privileges each time, but opinions of people with more experience are needed and would be highly appreciated. Thank you.</p>