Re: Determining the name of a global variable within a function
| From: | Scott S. Nicholson | Date: | Fri, 28 Jul 2000 16:43:20 +0000 |
| Subject: | Re: Determining the name of a global variable within a function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8814@lists.php.net to get a copy of this message | ||
> > I want to write a function that modifies a global array but returns a
> > different value. Is there any way (in PHP3) to determine the
> > global name of a variable passed to the function?
>
> I had to deal with something like this either earlier this week or
> late last week. But actually, now that I look at the code, the
> solution is pretty simple:
<snip>
> You don't need to use a global variable. Just pass your
> array as such:
>
> $bar = modify_array( &$foo );
>
> The '&' operator tells PHP to pass the array by reference
> and not by value.
Great. That'll work...
But I'd still like to hear if there's any way of doing it that doesn't
require passing the array by reference.
(basically I'm writing functions such as PHP4s array_shift() for PHP3, and
would like to be able to use them without having to remember the '&'...)
Thanks.
Scott
scottn@pnx1.com