php function inside another function
I have a function and I am trying to call that inside another function. i haven't done much php, so please clarify my question.
public function user($user)
{
if($user==''){
$this->logerror('not valid'); //this stores error in the db
return false;
}
}
I want t开发者_如何学Goo call the above function inside one main function, if I just do this way
public function main($username, $email) {
$this -> user($username);
//more code here to do something only if the user name is not empty
}
If i just do the main function like this, it stores the error saying "not valid" but the function continues. I understand that i am not returning anything so it does both the things, so how to stop the function if it's not valid username.
but if i just copy the content of the "user" function it works fine as it returns false. I assumed that calling the function user inside the main will do the same thing.
please advise.
regards
Just catch the return value and then do something with it
$result = $this->user($username);
if ($result === false) {
return false; // or something else
} else {
// Do something, if user() does not return 'false'
}
精彩评论