Re: Global Var Disappearing After Function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



APseudoUtopia wrote:
> On Mon, Mar 22, 2010 at 5:13 PM, Peter van der Does
> <pvanderdoes@xxxxxxxxx> wrote:
>> On Mon, 22 Mar 2010 16:58:33 -0400
>> APseudoUtopia <apseudoutopia@xxxxxxxxx> wrote:
>>
>>> Hey list,
>>>
>>> I have a very odd problem which has been driving me crazy for two
>>> days. I've been trying to debug my code and gave up. I finally coded a
>>> very simple representation of what the code does, and I get the same
>>> problem. However, I still don't understand what's causing it.
>>>
>>> The representational code:
>>> http://pastie.org/private/fz3lgvsjopz3dhid8cf9a
>>>
>>> As you can see, it's very simple. A variable is set, then a function
>>> is called which modifies the variable in the global scope. However,
>>> the modifications CANNOT BE SEEN after the function is called.
>>>
>>> The output from the script is here:
>>> http://pastie.org/private/29r5mrr1k7rtqmw7eyoja
>>>
>>> As you can see, the modifications in do_test() cannot be seen after
>>> the function is called.
>>>
>>> What is causing this? And how can I fix it?
>>>
>>> Thanks!
>>>
>> From PHP.net:
>>
>> If a globalized variable is unset() inside of a function, only the
>> local variable is destroyed. The variable in the calling environment
>> will retain the same value as before unset() was called. [1]
>>
>> [1] http://php.net/manual/en/function.unset.php
>>
>>
> 
> Ah ha! I was looking on the php.net/global page for hints, but didn't
> see any. I should've looked on the unset page. Thanks!


Really no reason to unset() it anyway since you do this:

$Session = $UserInfo;

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux