When a PHP function is called, and something is RETURNED, does it stop running the code under it?

I'm just learning other custom PHP code right now to understand and learn better. In the code below, this is part of a custom class. When I encode using if / else blocks, I format them like this ...

if(!$this->isLoggedIn()){
    //do stuff
}

But in the code below it is more like

if (! $this->isLoggedIn())
    return false;

Also in the function below you can see that there are a couple of times, what could be the RETURN value . So my question here is when RETURN is called , after that it does not run any code? How does this end the script for this function?

In this case, if this is done ...

if (! $this->isLoggedIn())
        return false;

Does code execution continue below?


Here is the function

<?PHP
private function logout($redir=true)
{
    if (! $this->isLoggedIn())
        return false;

    $this->obj->session->sess_destroy();

    if ($this->isCookieLoggedIn())
    {
        setcookie('user','', time()-36000, '/');
        setcookie('pass','', time()-36000, '/');
    }
    if (! $redir)
        return;

    header('location: '.$this->homePageUrl);
    die;
}
?>
+3
source share
4

.

PHP , , . include s, , ..

"" :

$test = "test";
return;
echo $test;

, , , , .

, :

public function echoString($string)
{
    if(!is_string($string))
    {
        return;
    }
    echo $string;
}
+11

...

, return , , , , . "" , . ( goto, , , .)

, , , :

<?php
function logout($redir=true)
{
    if ($this->isLoggedIn()) 
    {
        $this->obj->session->sess_destroy();

        if ($this->isCookieLoggedIn()) {
            setcookie('user','', time()-36000, '/');
            setcookie('pass','', time()-36000, '/');
        }

        if ($redir) {
            header('location: '.$this->homePageUrl);
            die;
        }
    }
}
?>

" " . , .

+1

, return, , return, .

PHP, script .

@jason, , , .

0

Source: https://habr.com/ru/post/1729006/


All Articles