Please, take a look at how I understand the render() function from helplers.php, called by the function apologize().
/** * Apologizes to user with message. */ function apologize($message) { render("apology.php", ["message" => $message]); } /** * Renders view, passing in values. */ function render($view, $values = []) { // if view exists, render it if (file_exists("../views/{$view}")) { // extract variables into local scope extract($values);
// render view (between header and footer) require("../views/header.php"); require("../views/{$view}"); require("../views/footer.php"); exit; } // else err else { trigger_error("Invalid view: {$view}", E_USER_ERROR); } } The function apologize takes one argument as its parameter - $message. Apologize() calls the render function that have two parameters: the variable $view, which is supposed to be the name of a file; and an array $values.
By passing $values = [] as a parameter I in fact say that this array can have any kind and any number of keys in it, correct?
The apologize () function calls the render() one with parameters "apology.php" and ["message" => $message]. Then checks if apology.php exists in the given folder. If yes, then it calls extract(["message" => $message]) function and thus creates a new variable $message, which now has the value $message. (question on this below). Open header.php, followed by apology.php, which uses that new $message variable, and finish by opening footer.php; therefore display the whole message starting from Sorry! (printed as it is because it is not a php, but html) followed by $message. If apology.php doesn't exist in the given folder, return error.
I am confused by this $message story. If I pass to the apologize() function the variable $message as its parameter, where do I get this message from? Or would it correct to assume that if I have a small program, in which I call apologize() function, I should create a variable $message (or any other name) and use something like readline() function to get that message, or hardcode the value in that variable?
Thank you!