Re: [PHP] globals in functions
On Saturday, April 13, 2002, at 01:37 PM, Paul Roberts wrote: Is there a quick way to set all variables as global so that they are avalible to a function, i'm doing an eval inside, so i need all the submitted variables to be avalible, or do i have to decalre them individualy. If you refer to a POST or GET (or COOKIE or SESSION or SERVER) variable as $_POST['variablename'] or $_GET['variablename'], then it will automatically be global. In PHP 4.1.x or later Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] globals in functions
1: Globals are bad...m'kay. You should never use globals. If your function needs a variable, you should pass it in. There are exceptions to this rule but it's not a good idea to program normally this way. 2: Is this a form? It sounds (from the way you word it) that the variables are part of a form. If so, pass $_POST into your form and it will be able to evaluate them. If it's METHOD=GET then use $_GET. This is also a much more generic way to program since if you add a new variable to the form, you don't have to make it global in this function. if (myFunction($_GET)){ echo Everything is hunky dory!; } else { echo Blow Chow; } function myFunction($formArray=null){ if (isNull($formArray){ return false; } if (isarray($formArray)){ return true; } else { return false; } } // function myFunction($formArray=null) WARNING: I have not tried the code above. Use at your own risk. But the concepts are there. * * Cal Evans * Journeyman Programmer * Techno-Mage * http://www.calevans.com * -Original Message- From: Paul Roberts [mailto:[EMAIL PROTECTED]] Sent: Saturday, April 13, 2002 12:37 PM To: [EMAIL PROTECTED] Subject: [PHP] globals in functions Is there a quick way to set all variables as global so that they are avalible to a function, i'm doing an eval inside, so i need all the submitted variables to be avalible, or do i have to decalre them individualy. Paul Roberts [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php