Re: Strange behaviour of static declared content.

From: Date: Thu, 18 Oct 2007 13:48:02 +0000
Subject: Re: Strange behaviour of static declared content.
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-263307@lists.php.net to get a copy of this message
Stut wrote: > Stut 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(); > > Actually, scratch that, won't work. Not even unsetting $f before > creating the new object works. This kinda sucks since it means PHP does > not support static function-scoped vars. Yeah I tried that same thing too and then wondered if I had misinterpreted how function-scoped statics worked. I've often used a method like: function Init() { static $bln_inited = false; if (!$bln_inited) { // Do stuff $bln_inited = true; } } I had always assumed that the static definition here was function-scoped... I guess I should have tested more but still it caught me off guard this morning when I played with it. Correct me if I'm wrong but does C++ not do it as both of us initially thought? e.g. static is function scoped rather than globally scoped when used within a class method? Col

« previous php.general (#263307) next »