Jump to content

Setting Application Global Values & Varibles in Included files


RedMaster

Recommended Posts

How can I allow functions to access session-wide or application-wide variable values without having to:

 

A) Pass them as arguments each time the function(s) is executed

B) Declare the requested values/variables global within each function that uses them

 

I'm trying to discover the best practice for this and I'm not sure either of the above are very efficient.

Ha I kind of wish there was a way to declare all my application-wide values global in the beginning and allow functions to access them.

 

Also,

 

If I have a html template file which contains only html and application varibles ($name. address, etc.) how can I read that file into being displayed in such a way that the html quotation marks will not require protective slashes to be included in the file itself and still have php do value replacement for the varibles ($name, $address, etc.) found within the file prior to the echo or printr commands?

 

 

Thanks for your time and assistance !

Link to comment
Share on other sites

The safest way to define these types of variables is to use constants, any other global data is considered volatile because it can be changed at any time.

 

Could that be done for a MySQL connection handle ?

 

No. Resources cannot be stored within constants. If you want to store things like connection resources, a registry (as ignace has mentioned) may be of use. Though these can often be just as volatile as global variables.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.