RedMaster Posted December 29, 2009 Share Posted December 29, 2009 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/186625-setting-application-global-values-varibles-in-included-files/ Share on other sites More sharing options...
trq Posted December 29, 2009 Share Posted December 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186625-setting-application-global-values-varibles-in-included-files/#findComment-985669 Share on other sites More sharing options...
RedMaster Posted December 29, 2009 Author Share Posted December 29, 2009 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/186625-setting-application-global-values-varibles-in-included-files/#findComment-985673 Share on other sites More sharing options...
ignace Posted December 29, 2009 Share Posted December 29, 2009 You could create a Config Singleton object that holds all your application-wide configuration or if you want to have an object to contain your objects you could use a Registry which is also a Singleton implementation. Quote Link to comment https://forums.phpfreaks.com/topic/186625-setting-application-global-values-varibles-in-included-files/#findComment-985674 Share on other sites More sharing options...
trq Posted December 29, 2009 Share Posted December 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/186625-setting-application-global-values-varibles-in-included-files/#findComment-985681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.