Search code examples
phpdumpvar-dump

double output for variable


I have this next function:

function checkLoggedIn($status, $redirect=TRUE){
    switch($status){
        case "yes":
            if(!isset($_SESSION["loggedIn"])){
                if($redirect) {
                    header("Location: login.php");
                    exit;
                } else {
                    $authenticated = false;
                }
            } else {
                checkLoggedIn("no");
            }
        break;

        case "no":
            if(isset($_SESSION["loggedIn"]) && $_SESSION["loggedIn"] === true ){
                $authenticated = true;
            }
        break;
    }
    var_dump($authenticated);
    return $authenticated;
}

The strange this is that when I enable var_dump($authenticated);, I get as output if true:

bool(true)
NULL

and just

bool(false)

if false

Any ideas why?


Solution

  • That's because you are calling checkLoggedIn() inside itself.