Re: [PHP-DEV] Bug #331: static variables in object methods broken From: Zeev Suraski (bourbon <email protected>)
Date: 04/29/98

Good call. I can fix static so it would work inside objects, but I think
it's generally a bad idea, as the same static variable would be shared
among all objects of that type. You should really use some property
instead, e.g. $this->a.

I think the best thing would be generating a warning in case static is
declared inside member functions, but I can also make it work like in
regular functions. What do you guys think?

Zeev

At 20:49 29/04/98 -0000, jdavis <email protected> wrote:
>From: jdavis <email protected>
>Operating system: linux
>PHP version: 3.0 Release Candidate 4
>PHP Bug Type: Other
>Bug description:
>sorry if i'm missing something but it would seem that the
>following code should output:
>
>1
>2
>3
>
>instead $a never is set so it doesn't output anyting (except
>the "<p>\n" part)
>
>thank you and pls let me know if you need more info
>-----
>
>class foobar {
>
> function init () {
>
> static $a=1;
>
> print $a;
> print "<p>\n";
>
> $a++;
> }
>};
>
>$bar = new foobar; $bar->init(); $bar->init();
>$bar->init();
>
>

--
Zeev Suraski   <zeev <email protected>>
For a PGP public key, finger bourbon <email protected>