Re: Strange behaviour of static declared content.
| From: | Nathan Nobbe | Date: | Thu, 18 Oct 2007 11:40:18 +0000 |
| Subject: | Re: Strange behaviour of static declared content. | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263297@lists.php.net to get a copy of this message | ||
On 10/18/07, Stut <stuttle@gmail.com> wrote:
>
> Joshua Bacher wrote:
> >> I can't touch the API.
> >>
> >> i have never use static variables inside of functions and likely never
> will.
> >> go for static class variables instead :)
> >>
> >> <?php
> >> class foo{
> >> public static $foobar = false;
> >> public function bar(){
> >> static $foobar=false;
> >> if (self::$foobar === False){
> >> self::$foobar='FUBeyondAllR';
> >> echo self::$foobar . "\n";
> >> }else{echo "already defined\n";}
> >> }
> >> }
> >>
> >> $f=new foo();
> >> $f->bar();
> >> $f->bar();
> >> foo::$foobar=false;
> >> $f->bar();
> >> ?>
> >>
> >> nathan@devel ~/working/www/siuConference $ php testScript.php
> >> FUBeyondAllR
> >> already defined
> >> FUBeyondAllR
> >>
> >> -nathan
> >
> > thats the solution for the wrong problem. it's not up to me to change
> > the API. the API is designed like i noted and i need a way to get around
> > this behaviour.
> >
> > thanks for your idea any further suggestions?
>
> In that case you need a new foo. That's the only way you're going to
> reset the internal static if the API doesn't give you a way to do it.
>
> $f=new foo();
> $f->bar();
> $f->bar();
> $g=new foo();
> $g->bar();
this doesnt work:
nathan@devel ~/working/www/siuConference $ php testScript.php
FUBeyondAllR
already defined
already defined
already defined
-nathan