mindapolis Posted September 9, 2011 Share Posted September 9, 2011 Sorry, this will be a simple question. Say you define two global variables in your functions.php file as: GLOBAL $salesTax = .07; GLOBAL $shipping = 5.00; Those variables would be accessiible in the checkout.php page, right? Quote Link to comment https://forums.phpfreaks.com/topic/246808-global-variable-question/ Share on other sites More sharing options...
ManiacDan Posted September 9, 2011 Share Posted September 9, 2011 This is far too vague to be answered properly. The "global" keyword is not to be used like that, you use it for importing variables INTO functions, not usually for exporting them out into the global scope. That being said, it's almost always the wrong decision anyway. Globals are dangerous and break the flow of your application. Anything that exists in the global scope is automatically available in the global scope (persisting through include files). Things in the global scope are not available inside of functions or classes. Any items a function needs to do its job should be passed into the function as arguments. Any items the function needs to change should be returned by the function OR passed in by-reference so they can be changed inside the function without having to be returned. In general, "global" should not appear in your codebase. It's a hack. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/246808-global-variable-question/#findComment-1267466 Share on other sites More sharing options...
mindapolis Posted September 9, 2011 Author Share Posted September 9, 2011 thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/246808-global-variable-question/#findComment-1267470 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.