Re: Referencing a "constant" class variable
| From: | Daniel Schierbeck | Date: | Wed, 06 Oct 2004 18:52:39 +0000 |
| Subject: | Re: Referencing a "constant" class variable | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198767@lists.php.net to get a copy of this message | ||
Greg Donald wrote:
On Wed, 6 Oct 2004 13:02:18 -0500, Greg Donald <destiney@gmail.com> wrote:class MyClass { public static $myClassVar = "Bob"; } echo MyClass::$myClassVar; // Bob -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/register&r=6584On Wed, 6 Oct 2004 11:08:22 -0500, Chris Boget <chris.boget@wild.net> wrote:That's wrong, I was thinking of functions. Sorry. Seems you have to instantiate the class. class MyClass {If I have a class that looks like this: class MyClass { var $MyClassVar = "Bob"; } is there a way to reference that variable w/o instantiating MyClass? I've tried:MyClass::MyClassVarvar $MyClassVar = "Bob";} $class = new MyClass; echo $class->MyClassVar; I believe you can make the property static (at least in PHP5):