I have a function, where if a variable is not defined, exit; is called, therefor it should not produce anything on the page but a blank page. it produces an error message right before it is exited actually. so when its supposed to execute, because the variable is not defined, it should die, but what happens is the error message is executed, then the rest of the page loads under the error message, and does not exit. any ideas?
public function exit_error() {
parent::error_array();
$errors = $this->msg_array;
return $errors;
die(); // error should produce, then die here.
}
With this line:
the function exits and returns the result to the caller.
Anything that comes after the
returnstatement is never executed!You can think about
returnas letting the function say: “Here take this, I am finished here!”.Because of this it is possible to have multiple return statements in a function e.g :
The function is nonsense, the point is that if
$iis larger then0, the statementreturn 'foo'is reached, the function exists and never executes the following lines.With this you can leave a function early without doing further computations that might not be necessary.