Re: Static vars in methods

From: Date: Fri, 09 Mar 2001 16:54:20 +0000
Subject: Re: Static vars in methods
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-48417@lists.php.net to get a copy of this message
this sounds like a bad thing, especially if people start depending on that behavior.... -Jason ----- Original Message ----- From: "Andrei Zmievski" <andrei@ispi.net> To: "PHP Developers" <php-dev@lists.php.net> Cc: "Zeev Suraski" <zeev@zend.com>; "Andi Gutmans" <andi@zend.com> Sent: Friday, March 09, 2001 10:50 AM Subject: [PHP-DEV] Static vars in methods > Just ran into something (well, actually searching for it) and wanted to > know what everyone's thoughts on this were and whether it should stay > that way. > > <?php > class Foo { > function get() > { > static $i = 0; > > return ++$i; > } > } > > $c1 = new Foo; > var_dump($c1->get()); > var_dump($c1->get()); > $c2 = new Foo; > var_dump($c2->get()); > ?> > > Outputs: > > int(1) > int(2) > int(3) > > Basically, the static variable keeps its value even between different > class instances. In my case, it actually helps me with something, but on > the other hand, it doesn't seem that it should be this way.. > > -Andrei > * I don't have a solution but I admire the problem. * > > -- > 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 (#48417) next »