Re: predefined variable scope

From: Date: Mon, 26 Jun 2000 07:28:32 +0000
Subject: Re: predefined variable scope
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3080@lists.php.net to get a copy of this message
On 26 Jun, Sean Harding wrote: > I'm having an issue with variable scope that I'm not able to find in the > docs (which probably just means I'm looking in the wrong place). > > I have a file with all of my standard stuff in it (colors, email addresses, > etc.) called "std-defines.inc." All of the pages on my site 'require()' > it. In std-defines.inc, I have defined a function exit_with_errors(). I call > this function anywhere in the page that I run into a problem. It prints out > formatted error text and does some basic cleanup. I recently added a bit to > send email to me whenever the function is called (it should be a rare > occurrence). I hoped to have it include basic info about the request > (QUERY_STRING, HTTP_REFERER, SCRIPT_NAME, etc.) in the email. But these > variables seem to be undefined in exit_with_errors(). Since I can > successfully print them directly from the source file, I assume this is an > problem with the scope of those variables. > > Is there some way that I can make those predefined variables available to > functions in my .inc files without just passing them as function arguments? > > Thanks. > > sean > I think you need to declare the variables as global in your function: http://www.php.net/manual/html/language.variables.scope.html gives some detail. Cheers -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#3080) next »