Re: PHP_SELF or REQUEST_URI within Function ?

From: Date: Fri, 31 Aug 2001 15:21:08 +0000
Subject: Re: PHP_SELF or REQUEST_URI within Function ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65492@lists.php.net to get a copy of this message
So sprach »Boget, Chris« am 2001-08-31 um 10:22:28 -0500 : > True. But take the following function: > > function processLotsOfFormVars() { > global $fieldOne, $fieldTwo, $fieldThree, $fieldFour; > global $fieldFive, $fieldSix, $fieldSeven; > global $PHP_SELF, $REQUEST_URI; > global $HTTP_REFERER; > > echo "Field One is: $fieldOne<br>\n"; > echo "Field Two is: $fieldTwo<br>\n"; > // etc > } > > OR you can do it this way: > > function processLotsOfFormVars() { > echo "Field One is: $GLOBALS[fieldOne]<br>\n"; > echo "Field Two is: $GLOBALS[fieldTwo]<br>\n"; > // etc > } Uh? I don't see it. The "matching" function 1 is: function processLotsOfFormVars() { global $fieldOne; global $fieldTwo; echo "Field One is: $fieldOne<br>\n"; echo "Field Two is: $fieldTwo<br>\n"; } this quite doesn't look as intimidating as the piece you wrote. And even if there are 10 lines of 'global', I still like it a lot better, because it CLEARLY shows which form vars are going to be used. One of the downside of PHP IMHO is, that you do not have to define variables. This leads to a lot of errors. At least there should be a "option", which forces you to define variables, like maybe so: dim $some_var; this leads to easier readable code IMHO. > variables in a function. Plus, if the function gets large, > it's easier to see where the value is coming from by using > the $GLOBALS variable. Now, that's the point I'm arguing here. I don't think so. Alexander Skwar -- How to quote: http://learn.to/quote (german) http://quote.6x.to (english) Homepage: http://www.digitalprojects.com | http://www.iso-top.de iso-top.de - Die günstige Art an Linux Distributionen zu kommen Uptime: 2 days 2 hours 10 minutes

« previous php.general (#65492) next »