Re: Bug or undocumented feature: static?

From: Date: Tue, 22 May 2001 18:00:15 +0000
Subject: Re: Bug or undocumented feature: static?
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-56309@lists.php.net to get a copy of this message
It is supposed to behave like this. We took the C++ model. Andi At 12:13 PM 5/22/2001 +0200, Ulf Wendel wrote:
Hi, I stepped into something yesterday I would call an undocumented feature or a bug, don't know if I should make a bug report. Here's the snippet: function bar() { static $j = 0; print ++$j; } class foo { function foo() {
    static $i = 0;
    print ++$i;
} function bar() {
    static $j = 0;
    print ++$j;
} }
$obj1 = new foo();     => prints 1
$obj2 = new foo();     => prints 2
$obj1->bar();          => prints 1
$obj2->bar();          => prints 2
bar();                 => prints 1
Looks like the static variable is not bound to the member functions of my objects. I expected that member functions from different objects of the same type do not share static variables, so that the output would be "11111". Ulf --
NetUSE AG              Dr.-Hell-Straße   Fon: +49 431 386 436 00
http://www.netuse.de/  D-24107 Kiel      Fax: +49 431 386 435 99
PHP lernen? Noch sind Schulungsplätze frei: http://www.netuse.de/ -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.dev (#56309) next »