RE: [PHP] Too much of $GLOBALS[] a problem??
Very Well Explained.. now I know how to use the code which I saw in phpMyAdmin or Tiki.. Much better way to do it and a lot less conflicts to as you say,variable names. Thanks. Cheers, Mun Heng, Ow H/M Engineering Western Digital M'sia DID : 03-7870 5168 -Original Message- From: Lars Torben Wilson [mailto:[EMAIL PROTECTED] Sent: Friday, July 18, 2003 12:26 PM To: Ow Mun Heng Cc: [EMAIL PROTECTED] Subject: RE: [PHP] Too much of $GLOBALS[] a problem?? On Thu, 2003-07-17 at 21:10, Ow Mun Heng wrote: > > 'Loosely-coupled' code relied much less on the environment around it. > > It would typically receive its values through an argument list, array > > of values it needs, or perhaps by being a method in a class which has > > attribute values for all of the necessary stuff. > > The $GLOBALS['parameter'] is actually defined in ONE(a config file that > houses all the parameters and another a language file) place where it can be > changed. So, i would say that's an argument list, is it not? No, it's a configuration file. An argument list is the bit between the parentheses when you write a function call: $retval = some_func($this, $is, $the, $argument, $list); If your config file had all of those variables in an array or something, and you passed that array to your function, *that* would be an argument list. See below: config.php: 1, 'overall_summary' => 'Here is the summary', etc); ?> script.php: Problem solved. The only thing left which can conflict is the name $config, and you could solve that by calling it something you're sure nobody else will be using (maybe $_omh_config or something). Now, you can lift your config file and display_menu_html() function and drop them into pretty much any script and be much more sure that you won't have to crawl through all the code making sure there are no variable name conflicts. > The other way would be to write a function that obtains that from the > argument list. But as I see it, it's basically the same thing? NO? No, because say you want to use this function in another script. First you need to make sure that this new script isn't already using any globals with any of the names you want to use--otherwise, you'll have variable clashes--where you expect one thing to be in $logout, for instance, but the script is using the name $logout for something else, and the value isn't what you expect. > Class.. That's not somewhere I would want to venture, not right now anyway. > Just starting out. > > Cheers, > Mun Heng, Ow > H/M Engineering > Western Digital M'sia > DID : 03-7870 5168 There was a discussion on this list about programming practices and books about programming--I think last week or the week before. Try a search on the archives. Anyway, there are lot of great books on programming which should help--and excellent and easy-to-read book which covers a lot of things which you *don't* want to have to figure out yourself is 'Code Complete', by Steve McConnell. -- Torben Wilson <[EMAIL PROTECTED]>+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Too much of $GLOBALS[] a problem??
Rather than having the following scenario: $GLOBALS['foo'] = 'foo'; $GLOBALS['fee'] = 'fee'; The following would be much cleaner and portable while still allowing the ease of use of $GLOBALS based configuration: $GLOBALS['myProjectName']['foo'] = 'foo'; $GLOBALS['myProjectName']['fee'] = 'fee'; Cheers, Rob. On Thu, 2003-07-17 at 22:58, Curt Zirzow wrote: > Ow Mun Heng <[EMAIL PROTECTED]> wrote: > > Hi All, > > > > Just a quick question on this. In my scripts, I'm using A LOT Of > > $GLOBALS['my_parameter'] to get the declared values/string. 1 example below > > : > > > > function display_menu_html() > > { > > echo ''."\n"; > > echo ''."\n"; > > echo "\t".''."\n"; > > echo "\t".'' . $GLOBALS['home'] . " > > > > [...] > > > > } > > > > This isn't really a Problem but.. is it bad programming practice?? Or I > > should just write another function that can return the values/string? > > > yes and no, that is rather a debatable question. > > To make my functions that echo stuff cleaner I usually do stuff like: > > function show_html() { > > > > > > > > ?> > } > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- .-. | Worlds of Carnage - http://www.wocmud.org | :-: | Come visit a world of myth and legend where | | fantastical creatures come to life and the | | stuff of nightmares grasp for your soul.| `-' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Too much of $GLOBALS[] a problem??
On Thu, 2003-07-17 at 21:10, Ow Mun Heng wrote: > > 'Loosely-coupled' code relied much less on the environment around it. > > It would typically receive its values through an argument list, array > > of values it needs, or perhaps by being a method in a class which has > > attribute values for all of the necessary stuff. > > The $GLOBALS['parameter'] is actually defined in ONE(a config file that > houses all the parameters and another a language file) place where it can be > changed. So, i would say that's an argument list, is it not? No, it's a configuration file. An argument list is the bit between the parentheses when you write a function call: $retval = some_func($this, $is, $the, $argument, $list); If your config file had all of those variables in an array or something, and you passed that array to your function, *that* would be an argument list. See below: config.php: 1, 'overall_summary' => 'Here is the summary', etc); ?> script.php: Problem solved. The only thing left which can conflict is the name $config, and you could solve that by calling it something you're sure nobody else will be using (maybe $_omh_config or something). Now, you can lift your config file and display_menu_html() function and drop them into pretty much any script and be much more sure that you won't have to crawl through all the code making sure there are no variable name conflicts. > The other way would be to write a function that obtains that from the > argument list. But as I see it, it's basically the same thing? NO? No, because say you want to use this function in another script. First you need to make sure that this new script isn't already using any globals with any of the names you want to use--otherwise, you'll have variable clashes--where you expect one thing to be in $logout, for instance, but the script is using the name $logout for something else, and the value isn't what you expect. > Class.. That's not somewhere I would want to venture, not right now anyway. > Just starting out. > > Cheers, > Mun Heng, Ow > H/M Engineering > Western Digital M'sia > DID : 03-7870 5168 There was a discussion on this list about programming practices and books about programming--I think last week or the week before. Try a search on the archives. Anyway, there are lot of great books on programming which should help--and excellent and easy-to-read book which covers a lot of things which you *don't* want to have to figure out yourself is 'Code Complete', by Steve McConnell. -- Torben Wilson <[EMAIL PROTECTED]>+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Too much of $GLOBALS[] a problem??
On Thu, 2003-07-17 at 18:35, Ow Mun Heng wrote: > Hi All, > > Just a quick question on this. In my scripts, I'm using A LOT Of > $GLOBALS['my_parameter'] to get the declared values/string. 1 example below > : The only real problem is if you ever want to use that code in anything else. Using lots of globals will make that harder, since it will mean that you cannot simply lift that function out and drop it into some other chunk of code without making sure that the new global space contains all those globals, and that they contain what you expect. This is called 'tightly-coupled' code. It's just harder to reuse. 'Loosely-coupled' code relied much less on the environment around it. It would typically receive its values through an argument list, array of values it needs, or perhaps by being a method in a class which has attribute values for all of the necessary stuff. Other than that, it's not a huge issue. -- Torben Wilson <[EMAIL PROTECTED]>+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Too much of $GLOBALS[] a problem??
> 'Loosely-coupled' code relied much less on the environment around it. > It would typically receive its values through an argument list, array > of values it needs, or perhaps by being a method in a class which has > attribute values for all of the necessary stuff. The $GLOBALS['parameter'] is actually defined in ONE(a config file that houses all the parameters and another a language file) place where it can be changed. So, i would say that's an argument list, is it not? The other way would be to write a function that obtains that from the argument list. But as I see it, it's basically the same thing? NO? Class.. That's not somewhere I would want to venture, not right now anyway. Just starting out. Cheers, Mun Heng, Ow H/M Engineering Western Digital M'sia DID : 03-7870 5168 -Original Message- From: Lars Torben Wilson [mailto:[EMAIL PROTECTED] Sent: Friday, July 18, 2003 12:05 PM To: Ow Mun Heng Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Too much of $GLOBALS[] a problem?? On Thu, 2003-07-17 at 18:35, Ow Mun Heng wrote: > Hi All, > > Just a quick question on this. In my scripts, I'm using A LOT Of > $GLOBALS['my_parameter'] to get the declared values/string. 1 example below > : The only real problem is if you ever want to use that code in anything else. Using lots of globals will make that harder, since it will mean that you cannot simply lift that function out and drop it into some other chunk of code without making sure that the new global space contains all those globals, and that they contain what you expect. This is called 'tightly-coupled' code. It's just harder to reuse. Other than that, it's not a huge issue. -- Torben Wilson <[EMAIL PROTECTED]>+1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com - Boycott Starbucks! http://www.haidabuckscafe.com - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Too much of $GLOBALS[] a problem??
Ow Mun Heng <[EMAIL PROTECTED]> wrote: > Hi All, > > Just a quick question on this. In my scripts, I'm using A LOT Of > $GLOBALS['my_parameter'] to get the declared values/string. 1 example below > : > > function display_menu_html() > { > echo ''."\n"; > echo ''."\n"; > echo "\t".''."\n"; > echo "\t".'' . $GLOBALS['home'] . " > > [...] > > } > > This isn't really a Problem but.. is it bad programming practice?? Or I > should just write another function that can return the values/string? yes and no, that is rather a debatable question. To make my functions that echo stuff cleaner I usually do stuff like: function show_html() { ?> } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Too much of $GLOBALS[] a problem??
Ow Mun Heng wrote: This isn't really a Problem but.. is it bad programming practice?? Or I should just write another function that can return the values/string? I don't see why it would be, unless you don't like how it looks. -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Too much of $GLOBALS[] a problem??
Hi All, Just a quick question on this. In my scripts, I'm using A LOT Of $GLOBALS['my_parameter'] to get the declared values/string. 1 example below : function display_menu_html() { echo ''."\n"; echo ''."\n"; echo "\t".''."\n"; echo "\t".'' . $GLOBALS['home'] . " |\n"; echo "\t".'' . $GLOBALS['view_tracker'] . " |\n"; echo "\t".'' . $GLOBALS['initialise_fa'] . " |\n"; echo "\t".'' . $GLOBALS['mass_initialiase_fa'] . " |\n"; echo "\t".'' . $GLOBALS['overall_summary'] . " |\n"; echo "\t".'' . $GLOBALS['edit_account'] . " |\n"; echo "\t".'' . $GLOBALS['logout'] . " |\n"; echo "\t\n"; echo "\t".''."\n"; echo "\t".''."\n"; echo "\t".''."\n"; echo "\t".' '."\n"; echo "\n"; echo "\t\n"; echo "\n"; echo "\n"; } This isn't really a Problem but.. is it bad programming practice?? Or I should just write another function that can return the values/string? Any thots? Cheers, Mun Heng, Ow H/M Engineering Western Digital M'sia DID : 03-7870 5168 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php