Matt Elhotiby
Matt Elhotiby

Reputation: 44066

Does a php return exit out like break?

I was looking at this function and noticed a few returns....does a php return leave the function or does it continue down till the bottom

function confirmUser($username, $password) {
    global $conn; /* Add slashes if necessary (for query) */
    if (!get_magic_quotes_gpc()) {
        $username = addslashes($username);
    }

    /* Verify that user is in database */
    $q = "select password from users where username = '$username'";
    $result = mysql_query($q, $conn);
    if (!$result || (mysql_numrows($result) < 1)) {
        return 1; //Indicates username failure
    }

    /* Retrieve password from result, strip slashes */
    $dbarray = mysql_fetch_array($result);
    $dbarray['password'] = stripslashes($dbarray['password']);
    $password = stripslashes($password);

    /* Validate that password is correct */
    if ($password == $dbarray['password']) {
        return 0; //Success! Username and password confirmed
    } else {
        return 2; //Indicates password failure
    }
}

Upvotes: 1

Views: 2945

Answers (2)

Jason McCreary
Jason McCreary

Reputation: 72961

Returns from the function. Check out the docs - http://php.net/return

Upvotes: 4

Matthew
Matthew

Reputation: 48284

It immediately leaves the function at the place it is called.

Upvotes: 4

Related Questions