Re: Referencing a "constant" class variable
| From: | M. Sokolewicz | Date: | Wed, 06 Oct 2004 19:42:23 +0000 |
| Subject: | Re: Referencing a "constant" class variable | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-198769@lists.php.net to get a copy of this message | ||
Chris Boget wrote:
class MyEnums { var $this = 'This'; var $that = 'That'; var $other = 'Other'; } class MyClass { var $MyVar = MyEnums::this; } reference like MyClass::MyVar. Don't use PHP5 conventions in PHP4!I believe you can make the property static (at least in PHP5): class MyClass { public static $myClassVar = "Bob"; } echo MyClass::$myClassVar; // BobUnfortunately, in PHP4.3.2 that doesn't seem to be working... :( Does anyone know how I can access a class' variable w/o having to instantiate an object of the class? This is more to the point of what I'm trying to do: Since PHP4 doesn't have enums, I'm doing this: class MyEnums { var $this = 'This'; var $that = 'That'; var $other = 'Other'; } class MyClass { var $MyVar = MyEnums::$this; } But obviously, that's not working. Is there a way I can get it to work? thnx, Chris