Re: Strange behaviour of static declared content.
| From: | Stut | Date: | Thu, 18 Oct 2007 11:32:37 +0000 |
| Subject: | Re: Strange behaviour of static declared content. | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263295@lists.php.net to get a copy of this message | ||
Joshua Bacher wrote:
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(); -Stut -- http://stut.net/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?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