Wednesday, November 17, 2004

Function Calls at Runtime

It is possible to select the correct function to call at run-time ... here's how:


function requestLogin() {

print("Please login first.
");

}

function welcomeUser() {

print("Welcome to my homepage.
");

}

function checkUser($userLogin) {

global $runFunction;

if ($userLogin) {

$runFunction = "welcomeUser";

} else {

$runFunction = "requestLogin";

}

$runFunction();

}

$userLogin = true;

checkUser($userLogin);

$userLogin = false;

checkUser($userLogin);

?>

prints:

Welcome to my homepage.
Please login first.

0 Comments:

Post a Comment

<< Home