Re: static class member variables ?

From: Date: Tue, 12 Dec 2000 08:27:29 +0000
Subject: Re: static class member variables ?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-29842@lists.php.net to get a copy of this message
Assuming that you mean what I think you mean, you can sorta fake it. class simulate_static_vars{ function static_var($name,$newvalue="DUMMY_VALUE"){ static $static_vars; if("DUMMY_VALUE"!=$newvalue){ $static_vars[$name]=$newvalue; } $retval=$static_vars[$name]; return $retval; } function func1(){ $x=$this->static_var("x"); $x++; echo $x; $this->static_var("x",$x); } function func2(){ $x=$this->static_var("x"); $x++; echo $x; $this->static_var("x",$x); } } $x=new simulate_static_vars; $y=new simulate_static_vars; $x->func1(); $x->func2(); $y->func1(); $y->func2(); $x->func1(); $x->func2(); should print: 123456 This is kinda similar to how session vars work, you just have to remember to 'load' each pseudo static var you need to use in a function, and to 'save' any changes. If the vars don't need them to be static across different functions, you can save yourself plenty of trouble by just using 'static'. Richard Lynch wrote: > > Subject: [PHP] static class member variables ? > > > is this possible ? > > Not currently. > > No guesses about when they might be either. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#29842) next »