Re: Opinion about the using $GLOBALS directly
| From: | Stut | Date: | Wed, 19 Dec 2007 17:22:01 +0000 |
| Subject: | Re: Opinion about the using $GLOBALS directly | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-266111@lists.php.net to get a copy of this message | ||
Zoltán Németh wrote:
2007. 12. 19, szerda keltezéssel 10.25-kor Richard Lynch ezt írta:Indeed. -Stut -- http://stut.net/On Wed, December 19, 2007 10:14 am, Stut wrote:well, if you have a long and complex function declaration which begins with global $whatever, and then all over the function $whatever is used, some dozens of lines later when looking for something in the code you might not have any idea that $whatever is global... however if you used $GLOBALS['whatever'] everywhere it would be trivial.Richard Lynch wrote:Since the global keyword MEANS that the variable is in the global scope, I'm having a hard time seeing how it's less clear that the variable is in the global scope...On Wed, December 19, 2007 4:13 am, Sancar Saran wrote:I would have to disagree. Using the global keyword makes it less obvious that the variable your dealing with is in the global scope. Using $GLOBALS instead makes it clear to anyone looking at the code that you're dealing with a global variable.I want know to you opinions about using $GLOBALS directly. like $GLOBALS['myString'] = 'test'; $GLOBALS['myArray']['this'] = 'this'; $GLOBALS['myArray']['that'] = 'that'; $GLOBALS['myClassObj] = new SomeClass;Don't. You are using global variables, and you might as well admit it and use the 'global' keyword to designate them as such. Poking stuff into $GLOBALS instead just makes it look like you're trying to pretend you're not using global variables when you are, to me. I did form this opinion before altering $GLOBALS was a documented feature.