note 39562 added to language.oop
| From: | beoran at mail15 dot com | Date: | Mon, 02 Feb 2004 14:06:10 +0000 |
| Subject: | note 39562 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64551@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39562
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39562&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39562&report=yes
Search -- http://master.php.net/manage/user-notes.php