Is it good practice to initialize a global variable in PHP? The snippet of code seems to work fine, but is it better to initialize (in a larger project, say for performance sake) the variable outside of a function, like in the second scratch of code?
if(isset($_POST["Return"]))Validate();
function Validate(){
(!empty($_POST["From"])&&!empty($_POST["Body"]))?Send_Email():Fuss();
};
function Send_Email(){
global $Alert;
$Alert="Lorem Ipsum";
mail("","",$_POST["Body"],"From:".$_POST["From"]);
};
function Fuss(){
global $Alert;
$Alert="Dolor Sit"
};
function Alert(){
global $Alert;
if(!is_null($Alert))echo $Alert;
};
Notice the variable $Alert above is not initialized.
$Alert;
if(isset($_POST["Return"]))Validate();
function Validate(){
(!empty($_POST["From"])&&!empty($_POST["Body"]))?Send_Email():Fuss();
};
function Send_Email(){
global $Alert;
$Alert="Lorem Ipsum";
mail("","",$_POST["Body"],"From:".$_POST["From"]);
};
function Fuss(){
global $Alert;
$Alert="Dolor Sit"
};
function Alert(){
global $Alert;
if(!is_null($Alert))echo $Alert;
};
Now notice it is.
I appreciate any answers! Thanks in advance, Jay