note 39562 deleted from language.oop by aidan

From: Date: Sat, 03 Jul 2004 14:49:55 +0000
Subject: note 39562 deleted from language.oop by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72437@lists.php.net to get a copy of this message
Note Submitter: beoran@mail15.com ---- Natedone's note below already shows some ways to implement static class members. There is another way that is based upon returning references, which may be of interest to you. class fooclass { function &staticvar() { static $staticvar; return $staticvar; } function printme() { print($this->staticvar()); } } $foo = new fooclass('foo'); $aid = & $foo->staticvar() ; $aid = "Hello"; $foo->printme(); // Prints "Hello" $aid = & $foo->staticvar() ; $aid = "Foo"; $foo->printme(); // Prints "Foo" This way to implement static class variables has as an advantage that you don't need to suse the same function to set and to get the value of a variable. The disadvantage is that you always need a helper variable.

« previous php.notes (#72437) next »