Hello John,

> From: JohnT [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, February 10, 2004 4:54 AM
> 
> Hello,
> 
> mind explain a little bit further cause i'm confused and not 
> sure if the
> fuction really work or something
> 
> [some Code]

As far as I know (or understand), unset() will only destroy the reference to a 
variable.

That's why you get sometimes a bit confusing results when unset variables insinde 
functions, because they are often just a reference or even a copy of another variable.
(for example using global $a; is equal to $a =& $GLOBALS['a'])

See:
  Chapter References Explained
   -> Unsetting References
  and Function Reference of unset()
of the php Manual.

Now I guess that a static variable is only available via reference in a function call.
Otherwise it would be unseted if the function call is finished, what's not the use of 
a static var.

How to fix this problem:
The purpose of your code was to reset the value of the static variable.
So just do this reseting by assigning the value you wanted, e.g.

///////////////   CODE   /////////////////
function foo() {
    static $a;
    $a++;
    echo "$a<BR>";
    $a = 0;
}

foo();
foo();
foo();
///////////////////////////////////////////////

Now it outputs:
1
1
1



Regards,
Dirk Oschlies

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

Reply via email to