vi390
12-10-2007, 09:25 AM
in terms of OOP we learn, that using Global values like $GLOBALS in PHP is a bad practice, and if ever Global Values have to be used it should be done with an Singleton Registry Pattern.
I have implemented both methods now, and have found out the following.
*The Registry Singleton is nice, since I can double check values before they get in there with the set method
*I have one capsulation container for Global Data
* I can Protect them for outside view
But on the other hand
* The $GLOBALS Array is just there to use already, its not a single lline of extra code necessary to make it work
* its just dropping some values, and get access there everywhere
* I can check the values with a check Class, and throw errors, if necessary I can call this whenever i want
* I still can use get, and set methods, to use this memory area, but I do not have to if I do not like it, and access it directly
* I can have direct access to the variables and arrays, without having to make some sort of special methods to access it directly
* Values do not have to be copied in the memory mapping to access them and to change them. Its just one place which holds them.
* for protected Data, you still can use a Singleton Registry if you need it, and it makes sence
* If I save something in $GLOBALS with $GLOBALS['myvalues']['part1_array'][] = "Hello World"; I just make print_r($GLOBALS['myvalues']); and I have everything important for Bugfixing. I will have to write an extra Method, If I want to do that with a Singleton Registry.
* Accessing A Global Array is faster, then getting it from Classes, It might be valuable on special Sites with loads of users.
So Iam just asking myself, Why would I have to use the Singleton Registry Method again. I understand that in an environment, where hundreds of Coders are working on a project, and where it has to be sort of an hierarchy of Coding, and protecting variables.
But if the project is some sort of MAIN code, forexample a Main Framework, where its Core is a Major DataBackBone Memspace, where all the values get gathered together. (Iam not talking about doing everything with a Superglobal Array,and forget about parameter passing, this would be Very Bad Practice, Iam just taliking about the absolute need of global available Data, and we all know, that there are situations , where you need that) Iam not talking about the reuse of this classes in every situation. Iam talking about classes which belong together and are not about to be ripped apart. Its a Key functionality of a System, and the $Globals is used with interfaces, not just accessed wildly, and uncontrolled.
I do NOT want to start Flamewars. I Just want to know and discuss Opinions for, or against the use of either $GLOBALS in special cases. And the Singleton Registry Pattern.
I have implemented both methods now, and have found out the following.
*The Registry Singleton is nice, since I can double check values before they get in there with the set method
*I have one capsulation container for Global Data
* I can Protect them for outside view
But on the other hand
* The $GLOBALS Array is just there to use already, its not a single lline of extra code necessary to make it work
* its just dropping some values, and get access there everywhere
* I can check the values with a check Class, and throw errors, if necessary I can call this whenever i want
* I still can use get, and set methods, to use this memory area, but I do not have to if I do not like it, and access it directly
* I can have direct access to the variables and arrays, without having to make some sort of special methods to access it directly
* Values do not have to be copied in the memory mapping to access them and to change them. Its just one place which holds them.
* for protected Data, you still can use a Singleton Registry if you need it, and it makes sence
* If I save something in $GLOBALS with $GLOBALS['myvalues']['part1_array'][] = "Hello World"; I just make print_r($GLOBALS['myvalues']); and I have everything important for Bugfixing. I will have to write an extra Method, If I want to do that with a Singleton Registry.
* Accessing A Global Array is faster, then getting it from Classes, It might be valuable on special Sites with loads of users.
So Iam just asking myself, Why would I have to use the Singleton Registry Method again. I understand that in an environment, where hundreds of Coders are working on a project, and where it has to be sort of an hierarchy of Coding, and protecting variables.
But if the project is some sort of MAIN code, forexample a Main Framework, where its Core is a Major DataBackBone Memspace, where all the values get gathered together. (Iam not talking about doing everything with a Superglobal Array,and forget about parameter passing, this would be Very Bad Practice, Iam just taliking about the absolute need of global available Data, and we all know, that there are situations , where you need that) Iam not talking about the reuse of this classes in every situation. Iam talking about classes which belong together and are not about to be ripped apart. Its a Key functionality of a System, and the $Globals is used with interfaces, not just accessed wildly, and uncontrolled.
I do NOT want to start Flamewars. I Just want to know and discuss Opinions for, or against the use of either $GLOBALS in special cases. And the Singleton Registry Pattern.