global vars within 2-level functions
| From: | Erik Price | Date: | Tue, 02 Apr 2002 18:11:11 +0000 |
| Subject: | global vars within 2-level functions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-91183@lists.php.net to get a copy of this message | ||
I have some code, in which I am using the function keyword to create subroutines of code (in otherwords, not true functions but rather reuseable chunks of other code).
Yeah, it's ugly, but I need to do it this way for now.
So my question is this: One of my subroutine/functions generates a variable. I would like to make this variable available to another subroutine/function, which is called from the first subroutine/function. If what I say is confusing, think of it like this:
function1
- creates variable_A
- calls function2
function2
- needs to access variable_A
The problem is that this variable is not available to function2, even if I use the "global" keyword. The only way I can pass this variable to function2 is if I pass it as an argument. However, in some cases, I need to call function2 without this argument, but this creates some Warnings which I don't want to see. I don't want to just suppress these warnings, how can I either
(a) Pass a variable from a function to a subfunction called from the first function
(b) Pass a variable as an argument to a function but make that argument optional so that it does not have to exist to make the function legitimate.
Thank you,
Erik
----
Erik Price
Web Developer Temp
Media Lab, H.H. Brown
pricee@hhbrown.com