Re: [PHP] Too much of $GLOBALS[] a problem??

2003-07-18 Thread Robert Cummings
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 'table class=width100 cellspacing=0'.\n;
  echo 'tr'.\n;
  echo \t.'td class=menu'.\n;
  echo \t.'a href=home.php' . $GLOBALS['home'] . /a
 
  [...]
   
  }
  
  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() {
 ?
 table class=width100 cellspacing=0
   tr
 td class=menu
   a href=someplace.php?php echo $var?/a
 /td
   /tr
 /table
 ?
 }
  
 
 
 -- 
 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??

2003-07-18 Thread Ow Mun Heng
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:
?php
$config = array('logout' = 1,
'overall_summary' = 'Here is the summary',
etc);
?

script.php:
?php
include('config.php');
display_menu_html($config);
?

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



[PHP] Too much of $GLOBALS[] a problem??

2003-07-17 Thread Ow Mun Heng
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 'table class=width100 cellspacing=0'.\n;
echo 'tr'.\n;
echo \t.'td class=menu'.\n;
echo \t.'a href=home.php' . $GLOBALS['home'] . /a
nbsp|\n;
echo \t.'a href=view_tracker.php' . $GLOBALS['view_tracker'] .
/a nbsp|\n;
echo \t.'a href=initialise_fa.php' . $GLOBALS['initialise_fa']
. /a nbsp|\n;
echo \t.'a href=mass_initialiase_fa.php' .
$GLOBALS['mass_initialiase_fa'] . /a nbsp|\n;
echo \t.'a href=Summary.php' . $GLOBALS['overall_summary'] .
/a nbsp|\n;
echo \t.'a href=account.php' . $GLOBALS['edit_account'] .
/a nbsp|\n;
echo \t.'a href=logout.php' . $GLOBALS['logout'] . /a
nbsp|\n;
echo \t/td\n;
echo \t.'td class=right style=white-space: nowrap'.\n; 
echo \t.'form input=post action=jump_to_fa.php'.\n;
echo \t.'input type=text name=fa_id size=12
class=bold-small /'.\n;
echo \t.'input type=submit value=' . $GLOBALS['goto_fa'] . '
class=small / '.\n;
echo /form\n;
echo \t/td\n;
echo /tr\n;
echo /table\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



Re: [PHP] Too much of $GLOBALS[] a problem??

2003-07-17 Thread Leif K-Brooks
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


Re: [PHP] Too much of $GLOBALS[] a problem??

2003-07-17 Thread Curt Zirzow
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 'table class=width100 cellspacing=0'.\n;
   echo 'tr'.\n;
   echo \t.'td class=menu'.\n;
   echo \t.'a href=home.php' . $GLOBALS['home'] . /a

 [...]

 }
 
 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() {
?
table class=width100 cellspacing=0
  tr
td class=menu
  a href=someplace.php?php echo $var?/a
/td
  /tr
/table
?
}
 


-- 
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??

2003-07-17 Thread Ow Mun Heng
 '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??

2003-07-17 Thread Lars Torben Wilson
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??

2003-07-17 Thread Lars Torben Wilson
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:
?php
$config = array('logout' = 1,
'overall_summary' = 'Here is the summary',
etc);
?

script.php:
?php
include('config.php');
display_menu_html($config);
?

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