Initialize Global Variables in PHP -


Is a good practice to start a global variable in PHP? The code snippet works fine, but is it better to start the variable outside of a function (called for a larger project, for performance) than the second start of the code?

  if (isset ($ _post ["The Return"])) Valid (); Function Validate () () (Fill ($ _ POST ["from"]) & amp; Empty ($ _ POST ["body"])) Send_Email (): fuse ();}; Send_Email () {global $ Alert; $ Alert = "Lomp Ipsum"; Mail ("", "", $ _ Post ["The Body"], "From:". $ _ Post ["From"]);}; Fuses Function () { Global $ Alert; $ Alert = "Put Dall"}; Function Alert () {Global $ Alert; if (! Is_null ($ Warning)) echo $ Alert;}  

The above variable $ Alert has not been started.

  $ alert; if (isset ($ _ post ["The Return"]) Valid (); Validate the function () ((empty ($ _ POST ["to"]) & amp; Empty ($ _ POST ["body"])) Send_Email (): fuse ();}; Send_Email function () {Global $ Alert; $ Alert = "Larm Ipsum"; Mail ("", "", $ _ Post ["The Body"], "From:". $ _ Post ["From"]);}; Fuse function () {global $ alert; $ alerts = "sit idle"}; function alert () {global $ alert; if (! Is_null ($ warning)) echo $ alert;}  

Now there is a notice.

I appreciate any answer! In the second example, you still have variables Damage are not, Line

P>

  $ warning;  

$ Warning does not specify the value, so it remains undeclared.

If you declare the first variable, you can access it easily without generating the notice:

  $ alert = ''; If ($ warning) {// do something with warning}  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -