Summary
I want a function to execute only if a certain variable is true
, however it checks the status of the variable before it exists.
Code
At the top of my PHP page I have:
$debug = true;
At the bottom, among other functions I have:
function debug($message){
echo ($debug ? "$message<br/>" : "");
}
And throughout the page I call:
debug("Debugging message here");
However, when I run the page with error reporting on, I get this error:
Notice: Undefined variable: debug in /examle.php on line 148
which references the middle line of the function.
Question
How can I make a function that prints data only if the variable $debug
, which is called at the top of the page, is true
?