Global Annoyance
| From: | Bill dot Hoffman at walgreens dot com | Date: | Mon, 18 Dec 2000 20:39:03 +0000 |
| Subject: | Global Annoyance | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-30914@lists.php.net to get a copy of this message | ||
I would first like to state that I have been using PHP for the last
year and think that it is the greatest thing since sliced bread. There is
one thing that has been annoying me that I have not found a way around and
thought I would find out if there were others like me. I do not like
having to declare a variable as global every time I use it in a function.
95% of the time the variables that I use I want to use throughout my whole
script. I like to use functions but when I do I must declare all of the
variables that I have already declared again in every function. Here is an
example in case I am being unclear:
function MailIt () {
global $rec;
global $subject;
global $boxstatus;
global $box;
global $body;
# call the mail function to mail admins
mail
(
"$rec",
"$subject",
"This E-mail has been sent due to $boxstatus on the currect box $box
$body"
)
}
$rec = me@you.com;
$subject = "test subject";
$boxstatus = "down";
$box = "prdbox";
$body = "This is where the body will go";
MailIt ();
I would like to have all of my variables available globally unless I specify otherwise. If I wanted
to make a second mail function I would have to
declare all of these
variables all over again. I have had to declare the same variable 5 times in 5 different functions.
Let me know if anyone knows a better way to do this.
Please respond to me via direct E-mail. The list stopped mailing to me months ago.
Thanx,
BEH