Jacemdom Posted October 16, 2006 Report Share Posted October 16, 2006 From Experts-Exchange newsletter : Global variables are a fact of life. Although global variables are technically never necessary, particularly in PHP programs that use object-oriented design, they often make programs easier to read and easier to write. There are definitely situations in which they are reasonable and appropriate: resources or handles returned from API calls that are used in many functions, frequently-used arguments passed in via GET or POST, and very long strings used in cryptological protocols are some cases that come to mind.The problem I have with global variables in PHP is that they work the opposite way they do in other languages: they are declared in each function, instead of at file level. This is about as verbose and difficult to maintain as passing each global variable used by a function in its argument list. Argument lists (or "global" statements) become longer, and must change wherever needed when a new global variable is added to the program. Quote Link to comment
i2dx Posted October 16, 2006 Report Share Posted October 16, 2006 From Experts-Exchange newsletter : that's why I allways use objects in PHP who needs globals, if he can access "his" variables in a proper designed "root object"? cheers, CB Quote Link to comment
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.