Re: Global Variables -- why not have them?
| From: | mike cullerton | Date: | Mon, 09 Jul 2001 02:31:19 +0000 |
| Subject: | Re: Global Variables -- why not have them? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-56857@lists.php.net to get a copy of this message | ||
on 7/8/01 7:57 PM, Brian White at bwhite@steptwo.com.au wrote:
>>> I dislike the GLOBAL statement in that many of the bugs that get me
>>> scratching my
>>> head are to do with when I have forgotten to use it.
>>
>> Then you're probably using it way too often.
>
> It is usually for "SCRIPT_NAME", or one of the CGI parameters.
>
> The CGI parameters are arguable, but I pretty much consider SCRIPT_NAME to be
> a global constant.
php does have constants which are _always_ global.
define ("SCRIPT_NAME", $passed_in_script);
then you refer to it like
my_function() {
printf("script is %s",SCRIPT_NAME);
}
notice there are no quotes or '$' or anything.
i've recently changed $DEBUG to DEBUG for things like
define("DEBUG", 1);
my_db_function() {
$rid = $db->query($query);
if (!DB::isError) {
do_something_cool();
} else {
if (DEBUG) printf("<!-- bummer, query failed : %s
-->\n",$rid->getMessage())
}
-- mike cullerton